@@ -57,7 +57,7 @@ |
||
57 | 57 | */ |
58 | 58 | public function addCurrency(Currency $currency) |
59 | 59 | { |
60 | - if($is_valid = $currency->validate()) { |
|
60 | + if ($is_valid = $currency->validate()) { |
|
61 | 61 | $this->currencies[] = $currency; |
62 | 62 | } else { |
63 | 63 | $this->errors['currency'][] = $currency->errors; |
@@ -331,7 +331,7 @@ |
||
331 | 331 | $this->params = $params; |
332 | 332 | return $this; |
333 | 333 | } |
334 | - /** |
|
334 | + /** |
|
335 | 335 | * @param mixed $params |
336 | 336 | * @return Offer |
337 | 337 | */ |
@@ -41,13 +41,13 @@ discard block |
||
41 | 41 | { |
42 | 42 | $this->writer->startElement('offer'); |
43 | 43 | $this->writer->writeAttribute('id', $this->id); |
44 | - if(null !== $this->type) $this->writer->writeAttribute('type', $this->type); |
|
44 | + if (null !== $this->type) $this->writer->writeAttribute('type', $this->type); |
|
45 | 45 | $this->writer->writeAttribute('available', $this->available ? 'true' : 'false'); |
46 | 46 | |
47 | - if(null !== $this->url) $this->writer->writeElement('url', $this->url); |
|
48 | - if(null !== $this->price) $this->writer->writeElement('price', $this->price); |
|
49 | - if(null !== $this->currencyId) $this->writer->writeElement('currencyId', $this->currencyId); |
|
50 | - if(null !== $this->categoryId) $this->writer->writeElement('categoryId', $this->categoryId); |
|
47 | + if (null !== $this->url) $this->writer->writeElement('url', $this->url); |
|
48 | + if (null !== $this->price) $this->writer->writeElement('price', $this->price); |
|
49 | + if (null !== $this->currencyId) $this->writer->writeElement('currencyId', $this->currencyId); |
|
50 | + if (null !== $this->categoryId) $this->writer->writeElement('categoryId', $this->categoryId); |
|
51 | 51 | |
52 | 52 | if (count($this->pictures) > 0) { |
53 | 53 | foreach ($this->pictures as $picture) { |
@@ -55,17 +55,17 @@ discard block |
||
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | - if($this->store) $this->writer->writeElement('store', $this->store ? 'true' : 'false'); |
|
59 | - if($this->delivery) $this->writer->writeElement('delivery', $this->delivery ? 'true' : 'false'); |
|
60 | - if(null !== $this->name) $this->writer->writeElement('name', $this->name); |
|
61 | - if(null !== $this->vendor) $this->writer->writeElement('vendor', $this->vendor); |
|
62 | - if(null !== $this->vendorCode) $this->writer->writeElement('vendorCode', $this->vendorCode); |
|
63 | - if(null !== $this->model) $this->writer->writeElement('model', $this->model); |
|
64 | - if(null !== $this->description) $this->writer->writeElement('description', $this->description); |
|
65 | - if(null !== $this->salesNotes) $this->writer->writeElement('sales_notes', $this->salesNotes); |
|
66 | - if(null !== $this->barcode) $this->writer->writeElement('barcode', $this->barcode); |
|
67 | - if(null !== $this->age) $this->writer->writeElement('age', $this->age); |
|
68 | - if($this->manufacturerWarranty) $this->writer->writeElement('manufacturer_warranty', $this->manufacturerWarranty ? 'true' : 'false'); |
|
58 | + if ($this->store) $this->writer->writeElement('store', $this->store ? 'true' : 'false'); |
|
59 | + if ($this->delivery) $this->writer->writeElement('delivery', $this->delivery ? 'true' : 'false'); |
|
60 | + if (null !== $this->name) $this->writer->writeElement('name', $this->name); |
|
61 | + if (null !== $this->vendor) $this->writer->writeElement('vendor', $this->vendor); |
|
62 | + if (null !== $this->vendorCode) $this->writer->writeElement('vendorCode', $this->vendorCode); |
|
63 | + if (null !== $this->model) $this->writer->writeElement('model', $this->model); |
|
64 | + if (null !== $this->description) $this->writer->writeElement('description', $this->description); |
|
65 | + if (null !== $this->salesNotes) $this->writer->writeElement('sales_notes', $this->salesNotes); |
|
66 | + if (null !== $this->barcode) $this->writer->writeElement('barcode', $this->barcode); |
|
67 | + if (null !== $this->age) $this->writer->writeElement('age', $this->age); |
|
68 | + if ($this->manufacturerWarranty) $this->writer->writeElement('manufacturer_warranty', $this->manufacturerWarranty ? 'true' : 'false'); |
|
69 | 69 | |
70 | 70 | if (count($this->params) > 0) { |
71 | 71 | foreach ($this->params as $param) { |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function addParam(OfferParam $param) |
141 | 141 | { |
142 | - if($param->validate()) { |
|
142 | + if ($param->validate()) { |
|
143 | 143 | $this->params[] = $param; |
144 | 144 | return true; |
145 | 145 | } else { |
146 | - $this->errors['params'][]=$param->errors; |
|
146 | + $this->errors['params'][] = $param->errors; |
|
147 | 147 | return false; |
148 | 148 | } |
149 | 149 | } |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | */ |
155 | 155 | public function addPicture(OfferPicture $picrure) |
156 | 156 | { |
157 | - if($picrure->validate()) { |
|
157 | + if ($picrure->validate()) { |
|
158 | 158 | $this->pictures[] = $picrure; |
159 | 159 | return true; |
160 | 160 | } else { |
161 | - $this->errors['pictures'][]=$picrure->errors; |
|
161 | + $this->errors['pictures'][] = $picrure->errors; |
|
162 | 162 | return false; |
163 | 163 | } |
164 | 164 | } |
@@ -41,13 +41,23 @@ discard block |
||
41 | 41 | { |
42 | 42 | $this->writer->startElement('offer'); |
43 | 43 | $this->writer->writeAttribute('id', $this->id); |
44 | - if(null !== $this->type) $this->writer->writeAttribute('type', $this->type); |
|
44 | + if(null !== $this->type) { |
|
45 | + $this->writer->writeAttribute('type', $this->type); |
|
46 | + } |
|
45 | 47 | $this->writer->writeAttribute('available', $this->available ? 'true' : 'false'); |
46 | 48 | |
47 | - if(null !== $this->url) $this->writer->writeElement('url', $this->url); |
|
48 | - if(null !== $this->price) $this->writer->writeElement('price', $this->price); |
|
49 | - if(null !== $this->currencyId) $this->writer->writeElement('currencyId', $this->currencyId); |
|
50 | - if(null !== $this->categoryId) $this->writer->writeElement('categoryId', $this->categoryId); |
|
49 | + if(null !== $this->url) { |
|
50 | + $this->writer->writeElement('url', $this->url); |
|
51 | + } |
|
52 | + if(null !== $this->price) { |
|
53 | + $this->writer->writeElement('price', $this->price); |
|
54 | + } |
|
55 | + if(null !== $this->currencyId) { |
|
56 | + $this->writer->writeElement('currencyId', $this->currencyId); |
|
57 | + } |
|
58 | + if(null !== $this->categoryId) { |
|
59 | + $this->writer->writeElement('categoryId', $this->categoryId); |
|
60 | + } |
|
51 | 61 | |
52 | 62 | if (count($this->pictures) > 0) { |
53 | 63 | foreach ($this->pictures as $picture) { |
@@ -55,17 +65,39 @@ discard block |
||
55 | 65 | } |
56 | 66 | } |
57 | 67 | |
58 | - if($this->store) $this->writer->writeElement('store', $this->store ? 'true' : 'false'); |
|
59 | - if($this->delivery) $this->writer->writeElement('delivery', $this->delivery ? 'true' : 'false'); |
|
60 | - if(null !== $this->name) $this->writer->writeElement('name', $this->name); |
|
61 | - if(null !== $this->vendor) $this->writer->writeElement('vendor', $this->vendor); |
|
62 | - if(null !== $this->vendorCode) $this->writer->writeElement('vendorCode', $this->vendorCode); |
|
63 | - if(null !== $this->model) $this->writer->writeElement('model', $this->model); |
|
64 | - if(null !== $this->description) $this->writer->writeElement('description', $this->description); |
|
65 | - if(null !== $this->salesNotes) $this->writer->writeElement('sales_notes', $this->salesNotes); |
|
66 | - if(null !== $this->barcode) $this->writer->writeElement('barcode', $this->barcode); |
|
67 | - if(null !== $this->age) $this->writer->writeElement('age', $this->age); |
|
68 | - if($this->manufacturerWarranty) $this->writer->writeElement('manufacturer_warranty', $this->manufacturerWarranty ? 'true' : 'false'); |
|
68 | + if($this->store) { |
|
69 | + $this->writer->writeElement('store', $this->store ? 'true' : 'false'); |
|
70 | + } |
|
71 | + if($this->delivery) { |
|
72 | + $this->writer->writeElement('delivery', $this->delivery ? 'true' : 'false'); |
|
73 | + } |
|
74 | + if(null !== $this->name) { |
|
75 | + $this->writer->writeElement('name', $this->name); |
|
76 | + } |
|
77 | + if(null !== $this->vendor) { |
|
78 | + $this->writer->writeElement('vendor', $this->vendor); |
|
79 | + } |
|
80 | + if(null !== $this->vendorCode) { |
|
81 | + $this->writer->writeElement('vendorCode', $this->vendorCode); |
|
82 | + } |
|
83 | + if(null !== $this->model) { |
|
84 | + $this->writer->writeElement('model', $this->model); |
|
85 | + } |
|
86 | + if(null !== $this->description) { |
|
87 | + $this->writer->writeElement('description', $this->description); |
|
88 | + } |
|
89 | + if(null !== $this->salesNotes) { |
|
90 | + $this->writer->writeElement('sales_notes', $this->salesNotes); |
|
91 | + } |
|
92 | + if(null !== $this->barcode) { |
|
93 | + $this->writer->writeElement('barcode', $this->barcode); |
|
94 | + } |
|
95 | + if(null !== $this->age) { |
|
96 | + $this->writer->writeElement('age', $this->age); |
|
97 | + } |
|
98 | + if($this->manufacturerWarranty) { |
|
99 | + $this->writer->writeElement('manufacturer_warranty', $this->manufacturerWarranty ? 'true' : 'false'); |
|
100 | + } |
|
69 | 101 | |
70 | 102 | if (count($this->params) > 0) { |
71 | 103 | foreach ($this->params as $param) { |
@@ -9,8 +9,8 @@ |
||
9 | 9 | |
10 | 10 | public function validate(Object &$object, array $attributes, array $options = []):void |
11 | 11 | { |
12 | - foreach ($attributes as $attribute){ |
|
13 | - if( !in_array($object->$attribute, $options)) { |
|
12 | + foreach ($attributes as $attribute) { |
|
13 | + if (!in_array($object->$attribute, $options)) { |
|
14 | 14 | $object->addError($attribute, $attribute.' must be element of ['.implode(', ', $options).']'); |
15 | 15 | } |
16 | 16 | } |
@@ -9,8 +9,8 @@ |
||
9 | 9 | |
10 | 10 | public function validate(Object &$object, array $attributes, array $options = []):void |
11 | 11 | { |
12 | - foreach ($attributes as $attribute){ |
|
13 | - if(!filter_var($object->$attribute, FILTER_VALIDATE_URL)) { |
|
12 | + foreach ($attributes as $attribute) { |
|
13 | + if (!filter_var($object->$attribute, FILTER_VALIDATE_URL)) { |
|
14 | 14 | $object->addError($attribute, $attribute.' must be valid url'); |
15 | 15 | } |
16 | 16 | } |
@@ -9,8 +9,8 @@ |
||
9 | 9 | |
10 | 10 | public function validate(Object &$object, array $attributes, array $options = []):void |
11 | 11 | { |
12 | - foreach ($attributes as $attribute){ |
|
13 | - if( strlen(trim( (string) $object->$attribute )) === 0) { |
|
12 | + foreach ($attributes as $attribute) { |
|
13 | + if (strlen(trim((string) $object->$attribute)) === 0) { |
|
14 | 14 | $object->addError($attribute, $attribute.' cannot be empty'); |
15 | 15 | } |
16 | 16 | } |
@@ -72,14 +72,14 @@ |
||
72 | 72 | throw new IncorrectRuleExceptin('Rule name must be a string'); |
73 | 73 | } |
74 | 74 | |
75 | - $class = '\\iamsaint\yml\\validators\\' . $rule[1]; |
|
75 | + $class = '\\iamsaint\yml\\validators\\'.$rule[1]; |
|
76 | 76 | |
77 | 77 | if (!class_exists($class)) { |
78 | 78 | throw new IncorrectRuleExceptin('Validator not found'); |
79 | 79 | } |
80 | 80 | |
81 | 81 | $attributes = is_array($rule[0]) ? $rule[0] : [$rule[0]]; |
82 | - (new $class())->validate($this, $attributes, $rule[2] ? : []); |
|
82 | + (new $class())->validate($this, $attributes, $rule[2] ?: []); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | return count($this->errors) === 0; |