From 6099df20c25093a8e9c516b889f1587cfcda7969 Mon Sep 17 00:00:00 2001 From: shap Date: Thu, 20 Sep 2018 15:59:06 +0300 Subject: [PATCH 1/2] the fix for the boolean uppercase-value attribute validation --- src/Offer/AOffer.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Offer/AOffer.php b/src/Offer/AOffer.php index 8140d7d..bdbcb15 100644 --- a/src/Offer/AOffer.php +++ b/src/Offer/AOffer.php @@ -204,15 +204,15 @@ public function isValid() $this->addError("Offer: incorrect value in attribute 'categoryId'"); } - if ($this->store !== null && $this->store !== 'true' && $this->store !== 'false') { + if ($this->store !== null && !$this->isValidBoolean($this->store)) { $this->addError("Offer: incorrect value in attribute 'store'"); } - if ($this->pickup !== null && $this->pickup !== 'true' && $this->pickup !== 'false') { + if ($this->pickup !== null && !$this->isValidBoolean($this->pickup)) { $this->addError("Offer: incorrect value in attribute 'pickup'"); } - if ($this->delivery !== null && $this->delivery !== 'true' && $this->delivery !== 'false') { + if ($this->delivery !== null && !$this->isValidBoolean($this->delivery)) { $this->addError("Offer: incorrect value in attribute 'delivery'"); } @@ -239,6 +239,12 @@ public function isValid() return empty($this->errors) && $subIsValid; } + private function isValidBoolean($attribute) + { + $lc_attr = lcfirst($attribute); + return $lc_attr === 'true' || $lc_attr === 'false'; + } + /** * @return array */ From 3b57e29a67be3f68f07f42c5afc1adf00f5b1c8b Mon Sep 17 00:00:00 2001 From: shap Date: Mon, 6 May 2019 11:58:27 +0300 Subject: [PATCH 2/2] node value "0" should not be replaced with "null" --- src/YML.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/YML.php b/src/YML.php index df898fe..ff1c293 100644 --- a/src/YML.php +++ b/src/YML.php @@ -194,7 +194,8 @@ protected function parseNode($basePath) } } } - $value = trim($value) ?: null; + $trimmedValue = trim($value); + $value = '' !== $trimmedValue ? $trimmedValue : null; return ['name' => $name, 'attributes' => $attributes, 'value' => $value, 'nodes' => $nodes]; }