Skip to content

Commit

Permalink
fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
lireincore committed May 13, 2017
1 parent d6c6679 commit 2a7c26e
Show file tree
Hide file tree
Showing 22 changed files with 132 additions and 130 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ try {
//...
}
} catch (\Exception $e) {
echo $e->getMessage();
//...
}
```
Expand Down
12 changes: 6 additions & 6 deletions src/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ class Category
public function isValid()
{
if ($this->id === null)
$this->setError("Category: missing required attribute 'id'");
$this->addError("Category: missing required attribute 'id'");
elseif (!is_numeric($this->id) || (int)$this->id <= 0)
$this->setError("Category: incorrect value in attribute 'id'");
$this->addError("Category: incorrect value in attribute 'id'");

if ($this->parentId !== null && (!is_numeric($this->parentId) || (int)$this->parentId <= 0))
$this->setError("Category: incorrect value in attribute 'parentId'");
$this->addError("Category: incorrect value in attribute 'parentId'");

if (!$this->name)
$this->setError("Category: incorrect value");
$this->addError("Category: incorrect value");

return empty($this->errors);
}
Expand All @@ -45,10 +45,10 @@ public function isValid()
* @param array $attributes
* @return $this
*/
public function setAttributes($attributes)
public function addAttributes($attributes)
{
foreach ($attributes as $name => $value) {
$this->setField($name, $value);
$this->addField($name, $value);
}

return $this;
Expand Down
14 changes: 7 additions & 7 deletions src/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ class Currency
public function isValid()
{
if ($this->id === null)
$this->setError("Currency: missing required attribute 'id'");
$this->addError("Currency: missing required attribute 'id'");
elseif (!in_array($this->id, ['RUR', 'RUB', 'UAH', 'BYN', 'BYR', 'KZT', 'USD', 'EUR']))
$this->setError("Currency: incorrect value in attribute 'id'");
$this->addError("Currency: incorrect value in attribute 'id'");

if ($this->rate === null)
$this->setError("Currency: missing required attribute 'rate'");
$this->addError("Currency: missing required attribute 'rate'");
elseif (!(in_array($this->rate, ['CBRF', 'NBU', 'NBK', 'CB']) || (is_numeric($this->rate) && (float)$this->rate > 0)))
$this->setError("Currency: incorrect value in attribute 'rate'");
$this->addError("Currency: incorrect value in attribute 'rate'");

if ($this->plus !== null && (!is_numeric($this->rate) || (int)$this->plus < 0))
$this->setError("Currency: incorrect value in attribute 'plus'");
$this->addError("Currency: incorrect value in attribute 'plus'");

return empty($this->errors);
}
Expand All @@ -49,10 +49,10 @@ public function isValid()
* @param array $attributes
* @return $this
*/
public function setAttributes($attributes)
public function addAttributes($attributes)
{
foreach ($attributes as $name => $value) {
$this->setField($name, $value);
$this->addField($name, $value);
}

return $this;
Expand Down
12 changes: 6 additions & 6 deletions src/DeliveryOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class DeliveryOption
public function isValid()
{
if ($this->cost === null)
$this->setError("DeliveryOption: missing required attribute 'cost'");
$this->addError("DeliveryOption: missing required attribute 'cost'");
elseif (!is_numeric($this->cost) || ((int)$this->cost) < 0)
$this->setError("DeliveryOption: incorrect value in attribute 'cost'");
$this->addError("DeliveryOption: incorrect value in attribute 'cost'");

if ($this->days === null)
$this->setError("DeliveryOption: missing required attribute 'days'");
$this->addError("DeliveryOption: missing required attribute 'days'");

if ($this->orderBefore !== null && (!is_numeric($this->orderBefore) || (int)$this->orderBefore < 0 || (int)$this->orderBefore > 24))
$this->setError("DeliveryOption: incorrect value in attribute 'order-before'");
$this->addError("DeliveryOption: incorrect value in attribute 'order-before'");

return empty($this->errors);
}
Expand All @@ -47,10 +47,10 @@ public function isValid()
* @param array $attributes
* @return $this
*/
public function setAttributes($attributes)
public function addAttributes($attributes)
{
foreach ($attributes as $name => $value) {
$this->setField($name, $value);
$this->addField($name, $value);
}

return $this;
Expand Down
8 changes: 4 additions & 4 deletions src/Offer/ABookOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ public function isValid()
$isValid = parent::isValid();

if ($this->name === null)
$this->setError("Offer: missing required attribute 'name'");
$this->addError("Offer: missing required attribute 'name'");

if ($this->year !== null && !is_numeric($this->year))
$this->setError("Offer: incorrect value in attribute 'year'");
$this->addError("Offer: incorrect value in attribute 'year'");

if ($this->volume !== null && (!is_numeric($this->volume) || (int)$this->volume <= 0))
$this->setError("Offer: incorrect value in attribute 'volume'");
$this->addError("Offer: incorrect value in attribute 'volume'");

if ($this->part !== null && (!is_numeric($this->part) || (int)$this->part <= 0))
$this->setError("Offer: incorrect value in attribute 'part'");
$this->addError("Offer: incorrect value in attribute 'part'");

return $isValid && empty($this->errors);
}
Expand Down
20 changes: 10 additions & 10 deletions src/Offer/AExtOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@ public function isValid()
$isValid = parent::isValid();

if ($this->fee !== null && (!is_numeric($this->fee) || (int)$this->fee <= 0))
$this->setError("Offer: incorrect value in attribute 'fee'");
$this->addError("Offer: incorrect value in attribute 'fee'");

if ($this->localDeliveryCost !== null && (!is_numeric($this->localDeliveryCost) || ((int)$this->localDeliveryCost) < 0))
$this->setError("Offer: incorrect value in attribute 'local_delivery_cost'");
$this->addError("Offer: incorrect value in attribute 'local_delivery_cost'");

if ($this->delivery === true && !$this->deliveryOptions && $this->localDeliveryCost == null)
$this->setError("Offer: attribute 'delivery-options' is required when 'delivery' is true");
$this->addError("Offer: attribute 'delivery-options' is required when 'delivery' is true");

if ($this->manufacturerWarranty !== null && $this->manufacturerWarranty !== 'true' && $this->manufacturerWarranty !== 'false')
$this->setError("Offer: incorrect value in attribute 'manufacturer_warranty'");
$this->addError("Offer: incorrect value in attribute 'manufacturer_warranty'");

if ($this->downloadable !== null && $this->downloadable !== 'true' && $this->downloadable !== 'false')
$this->setError("Offer: incorrect value in attribute 'downloadable'");
$this->addError("Offer: incorrect value in attribute 'downloadable'");

if ($this->adult !== null && $this->adult !== 'true' && $this->adult !== 'false')
$this->setError("Offer: incorrect value in attribute 'adult'");
$this->addError("Offer: incorrect value in attribute 'adult'");

$subIsValid = true;
if ($this->deliveryOptions) {
Expand Down Expand Up @@ -119,16 +119,16 @@ public function getErrors()
* @param array $attrNode
* @return $this
*/
public function setAttribute(array $attrNode)
public function addAttribute(array $attrNode)
{
if ($attrNode['name'] == 'delivery-options') {
foreach ($attrNode['nodes'] as $subNode) {
$this->addDeliveryOption((new DeliveryOption())->setAttributes($subNode['attributes']));
$this->addDeliveryOption((new DeliveryOption())->addAttributes($subNode['attributes']));
}
} elseif ($attrNode['name'] == 'age') {
$this->setAge((new Age())->setAttributes($attrNode['attributes'] + ['value' => $attrNode['value']]));
$this->setAge((new Age())->addAttributes($attrNode['attributes'] + ['value' => $attrNode['value']]));
} else {
parent::setAttribute($attrNode);
parent::addAttribute($attrNode);
}

return $this;
Expand Down
12 changes: 6 additions & 6 deletions src/Offer/AMainOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ public function isValid()
$isValid = parent::isValid();

if ($this->minQuantity !== null && (!is_numeric($this->minQuantity) || (int)$this->minQuantity <= 0))
$this->setError("Offer: incorrect value in attribute 'min-quantity'");
$this->addError("Offer: incorrect value in attribute 'min-quantity'");

if ($this->stepQuantity !== null && (!is_numeric($this->stepQuantity) || (int)$this->stepQuantity <= 0))
$this->setError("Offer: incorrect value in attribute 'step-quantity'");
$this->addError("Offer: incorrect value in attribute 'step-quantity'");

if ($this->groupId !== null && !is_numeric($this->groupId))
$this->setError("Offer: incorrect value in attribute 'group_id'");
$this->addError("Offer: incorrect value in attribute 'group_id'");

if ($this->from !== null && $this->from !== 'true' && $this->from !== 'false')
$this->setError("Price: incorrect value in attribute 'from'");
$this->addError("Price: incorrect value in attribute 'from'");

return $isValid && empty($this->errors);
}
Expand All @@ -85,13 +85,13 @@ public function isValid()
* @param array $attrNode
* @return $this
*/
/*public function setAttribute(array $attrNode)
/*public function addAttribute(array $attrNode)
{
//if ($attrNode['name'] == 'price') {
// if (isset($attrNode['attributes']['from'])) $this->setField('from', $attrNode['attributes']['from']);
//}
parent::setAttribute($attrNode);
parent::addAttribute($attrNode);
return $this;
}*/
Expand Down
50 changes: 25 additions & 25 deletions src/Offer/AOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,52 +145,52 @@ public function getAttributesList()
public function isValid()
{
if ($this->id === null)
$this->setError("Offer: missing required attribute 'id'");
$this->addError("Offer: missing required attribute 'id'");
elseif (!$this->id)
$this->setError("Offer: incorrect value in attribute 'id'");
$this->addError("Offer: incorrect value in attribute 'id'");

if ($this->bid !== null && (!is_numeric($this->bid) || (int)$this->bid <= 0))
$this->setError("Offer: incorrect value in attribute 'bid'");
$this->addError("Offer: incorrect value in attribute 'bid'");

if ($this->cbid !== null && (!is_numeric($this->cbid) || (int)$this->cbid <= 0))
$this->setError("Offer: incorrect value in attribute 'cbid'");
$this->addError("Offer: incorrect value in attribute 'cbid'");

if ($this->available === null) {
if ($this->getPickup())
$this->setError("Offer: attribute 'available' is required when 'pickup' is true");
$this->addError("Offer: attribute 'available' is required when 'pickup' is true");
}
elseif ($this->available !== 'true' && $this->available !== 'false')
$this->setError("Offer: incorrect value in attribute 'available'");
$this->addError("Offer: incorrect value in attribute 'available'");

if ($this->price === null)
$this->setError("Offer: missing required attribute 'price'");
$this->addError("Offer: missing required attribute 'price'");
elseif (!is_numeric($this->price) || (float)$this->price <= 0)
$this->setError("Offer: incorrect value in attribute 'price'");
$this->addError("Offer: incorrect value in attribute 'price'");

if ($this->oldprice !== null && (!is_numeric($this->oldprice) || (float)$this->oldprice <= (float)$this->price))
$this->setError("Offer: incorrect value in attribute 'oldprice'");
$this->addError("Offer: incorrect value in attribute 'oldprice'");

if ($this->currencyId === null)
$this->setError("Offer: missing required attribute 'currencyId'");
$this->addError("Offer: missing required attribute 'currencyId'");
elseif (!$this->currencyId)
$this->setError("Offer: incorrect value in attribute 'currencyId'");
$this->addError("Offer: incorrect value in attribute 'currencyId'");

if ($this->categoryId === null)
$this->setError("Offer: missing required attribute 'categoryId'");
$this->addError("Offer: missing required attribute 'categoryId'");
elseif (!$this->categoryId)
$this->setError("Offer: incorrect value in attribute 'categoryId'");
$this->addError("Offer: incorrect value in attribute 'categoryId'");

if ($this->store !== null && $this->store !== 'true' && $this->store !== 'false')
$this->setError("Offer: incorrect value in attribute 'store'");
$this->addError("Offer: incorrect value in attribute 'store'");

if ($this->pickup !== null && $this->pickup !== 'true' && $this->pickup !== 'false')
$this->setError("Offer: incorrect value in attribute 'pickup'");
$this->addError("Offer: incorrect value in attribute 'pickup'");

if ($this->delivery !== null && $this->delivery !== 'true' && $this->delivery !== 'false')
$this->setError("Offer: incorrect value in attribute 'delivery'");
$this->addError("Offer: incorrect value in attribute 'delivery'");

if ($this->weight !== null && (!is_numeric($this->weight) || (float)$this->weight <= 0))
$this->setError("Offer: incorrect value in attribute 'weight'");
$this->addError("Offer: incorrect value in attribute 'weight'");

$subIsValid = true;
if ($this->outlets) {
Expand Down Expand Up @@ -232,14 +232,14 @@ public function getErrors()
* @param array $offerNode
* @return $this
*/
public function setOffer(array $offerNode)
public function fillOffer(array $offerNode)
{
foreach ($offerNode['attributes'] as $name => $value) {
$this->setField($name, $value);
$this->addField($name, $value);
}

foreach ($offerNode['nodes'] as $attrNode) {
$this->setAttribute($attrNode);
$this->addAttribute($attrNode);
}

return $this;
Expand All @@ -249,23 +249,23 @@ public function setOffer(array $offerNode)
* @param array $attrNode
* @return $this
*/
public function setAttribute(array $attrNode)
public function addAttribute(array $attrNode)
{
if ($attrNode['name'] == 'outlets') {
foreach ($attrNode['nodes'] as $subNode) {
$this->addOutlet((new Outlet())->setAttributes($subNode['attributes']));
$this->addOutlet((new Outlet())->addAttributes($subNode['attributes']));
}
} elseif ($attrNode['name'] == 'picture') {
$this->addPicture($attrNode['value']);
} elseif ($attrNode['name'] == 'barcode') {
$this->addBarcode($attrNode['value']);
} elseif ($attrNode['name'] == 'param') {
$this->addParam((new Param())->setAttributes($attrNode['attributes'] + ['value' => $attrNode['value']]));
$this->addParam((new Param())->addAttributes($attrNode['attributes'] + ['value' => $attrNode['value']]));
} else {
if (!is_null($attrNode['value'])) $this->setField($attrNode['name'], $attrNode['value']);
if (!is_null($attrNode['value'])) $this->addField($attrNode['name'], $attrNode['value']);
if (!empty($attrNode['attributes'])) {
foreach ($attrNode['attributes'] as $name => $value) {
$this->setField($name, $value);
$this->addField($name, $value);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/Offer/Age.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class Age
public function isValid()
{
if ($this->unit === null)
$this->setError("Age: missing required attribute 'unit'");
$this->addError("Age: missing required attribute 'unit'");
elseif ($this->unit !== 'year' && $this->unit !== 'month')
$this->setError("Age: incorrect value in attribute 'unit'");
$this->addError("Age: incorrect value in attribute 'unit'");

if ($this->unit === 'year' && !in_array($this->value, ['0', '6', '12', '16', '18']))
$this->setError("Age: incorrect value");
$this->addError("Age: incorrect value");
elseif ($this->unit === 'month' && !in_array($this->value, ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']))
$this->setError("Age: incorrect value");
$this->addError("Age: incorrect value");

return empty($this->errors);
}
Expand All @@ -39,10 +39,10 @@ public function isValid()
* @param array $attributes
* @return $this
*/
public function setAttributes($attributes)
public function addAttributes($attributes)
{
foreach ($attributes as $name => $value) {
$this->setField($name, $value);
$this->addField($name, $value);
}

return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/Offer/ArtistTitleOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public function isValid()
$isValid = parent::isValid();

if ($this->title === null)
$this->setError("Offer: missing required attribute 'title'");
$this->addError("Offer: missing required attribute 'title'");

if ($this->year !== null && !is_numeric($this->year))
$this->setError("Offer: incorrect value in attribute 'year'");
$this->addError("Offer: incorrect value in attribute 'year'");

return $isValid && empty($this->errors);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Offer/BookOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function isValid()
$isValid = parent::isValid();

if ($this->pageExtent !== null && (!is_numeric($this->pageExtent) || (int)$this->volume <= 0))
$this->setError("Offer: incorrect value in attribute 'page_extent'");
$this->addError("Offer: incorrect value in attribute 'page_extent'");

return $isValid && empty($this->errors);
}
Expand Down
Loading

0 comments on commit 2a7c26e

Please sign in to comment.