diff --git a/ajax/activate.php b/ajax/activate.php index b84ce1082bdcad248149960b65389499ec6b56e0..138f7abb2c7198abd2e142c3cae6475c301a6e37 100644 --- a/ajax/activate.php +++ b/ajax/activate.php @@ -22,7 +22,7 @@ function ($discountId) { $Discount->setAttribute('active', 1); $Discount->update(); - return $Discount->isActive(); + return method_exists($Discount, 'isActive') ? $Discount->isActive() : false; }, ['discountId'], 'Permission::checkAdminUser' diff --git a/ajax/deactivate.php b/ajax/deactivate.php index d82213b85cdb306278a4cba0f91fd7d5760cb585..2ecbc737c2f24c207346eab0e0e78c9251f0401f 100644 --- a/ajax/deactivate.php +++ b/ajax/deactivate.php @@ -22,7 +22,7 @@ function ($discountId) { $Discount->setAttribute('active', 0); $Discount->update(); - return $Discount->isActive(); + return method_exists($Discount, 'isActive') ? $Discount->isActive() : false; }, ['discountId'], 'Permission::checkAdminUser' diff --git a/ajax/get.php b/ajax/get.php index 7a941df712e29a81218ee05b3f6379b480366092..c1aa502c5d77e7b8a457be0dd3af42f6f6e033f6 100644 --- a/ajax/get.php +++ b/ajax/get.php @@ -22,7 +22,7 @@ function ($id) { $attributes = $Discount->getAttributes(); /* @var $Discount Discount */ - $attributes['title'] = $Discount->getTitle(); + $attributes['title'] = method_exists($Discount, 'getTitle') ? $Discount->getTitle() : ''; return $attributes; }, diff --git a/ajax/search.php b/ajax/search.php index 0dfdbc15dbc5e7e7c0dfa2187107fe0f6858f075..f1a17067d9855d46dac9a34e90ba3a370e77c2fe 100644 --- a/ajax/search.php +++ b/ajax/search.php @@ -67,7 +67,7 @@ function ($fields, $params) { } usort($result, function ($a, $b) { - return $a['text'] > $b['text']; + return strcmp($a['text'], $b['text']); }); return $result; diff --git a/ajax/toggle.php b/ajax/toggle.php index 2ff6bc5c79523e9761dabcdca9a65cfdd62fbba0..8e318cba49f59c5eee78e76479b6c0acc2bb06e7 100644 --- a/ajax/toggle.php +++ b/ajax/toggle.php @@ -19,6 +19,10 @@ function ($discountId) { $Discount = $Handler->getChild($discountId); /* @var $Discount Discount */ + if (!method_exists($Discount, 'isActive')) { + return false; + } + if ($Discount->isActive()) { $Discount->setAttribute('active', 0); } else { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 74b2d37c7dfe87af6b0c178f3bf338249bd4d1b7..1339890a6e72c75d6ae49a176d1046f0c370282f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,46 +1,2 @@ parameters: - ignoreErrors: - - - message: "#^Call to an undefined method QUI\\\\CRUD\\\\Child\\:\\:isActive\\(\\)\\.$#" - count: 1 - path: ajax/activate.php - - - - message: "#^Call to an undefined method QUI\\\\CRUD\\\\Child\\:\\:isActive\\(\\)\\.$#" - count: 1 - path: ajax/deactivate.php - - - - message: "#^Call to an undefined method QUI\\\\CRUD\\\\Child\\:\\:getTitle\\(\\)\\.$#" - count: 1 - path: ajax/get.php - - - - message: "#^Parameter \\#2 \\$callback of function usort expects callable\\(mixed, mixed\\)\\: int, Closure\\(mixed, mixed\\)\\: bool given\\.$#" - count: 1 - path: ajax/search.php - - - - message: "#^Call to an undefined method QUI\\\\CRUD\\\\Child\\:\\:isActive\\(\\)\\.$#" - count: 2 - path: ajax/toggle.php - - - - message: "#^Call to method getArticles\\(\\) on an unknown class QUI\\\\ERP\\\\Order\\\\OrderInterface\\.$#" - count: 1 - path: src/QUI/ERP/Discount/Discount.php - - - - message: "#^Parameter \\#2 \\$array of function implode expects array\\|null, string given\\.$#" - count: 1 - path: src/QUI/ERP/Discount/Discount.php - - - - message: "#^Parameter \\$Order of method QUI\\\\ERP\\\\Discount\\\\Discount\\:\\:canUsedInOrder\\(\\) has invalid type QUI\\\\ERP\\\\Order\\\\OrderInterface\\.$#" - count: 2 - path: src/QUI/ERP/Discount/Discount.php - - - - message: "#^Parameter \\#2 \\$string of function explode expects string, float\\|int\\<min, \\-1\\>\\|int\\<1, max\\>\\|true given\\.$#" - count: 1 - path: src/QUI/ERP/Discount/PriceFactor.php + ignoreErrors: \ No newline at end of file diff --git a/src/QUI/ERP/Discount/Discount.php b/src/QUI/ERP/Discount/Discount.php index 399ae32bf3d5f0444e3467c7b50e899085505a57..a28e43ebad3723e3740958c11e618f6bf07f252f 100644 --- a/src/QUI/ERP/Discount/Discount.php +++ b/src/QUI/ERP/Discount/Discount.php @@ -248,7 +248,7 @@ public function setAttribute(string $name, mixed $value): void * @param null|QUI\Locale $Locale - optional, locale object * @return string */ - public function getTitle(QUI\Locale $Locale = null): string + public function getTitle(null | QUI\Locale $Locale = null): string { if (!$Locale) { $Locale = QUI::getLocale(); @@ -284,7 +284,7 @@ public function canCombinedWith(Discount $Discount): bool return false; } - $combine = implode($combine, ','); + $combine = implode(',', $combine); if (in_array($Discount->getId(), (array)$combine)) { return true; @@ -521,7 +521,7 @@ public function verifyUser(User $User): void public function toPriceFactor( $Locale = null, $Customer = null - ): QUI\ERP\Products\Interfaces\PriceFactorInterface|QUI\ERP\Products\Interfaces\PriceFactorWithVatInterface|QUI\ERP\Products\Utils\PriceFactor { + ): QUI\ERP\Products\Interfaces\PriceFactorInterface | QUI\ERP\Products\Interfaces\PriceFactorWithVatInterface | QUI\ERP\Products\Utils\PriceFactor { switch ($this->getAttribute('discount_type')) { case QUI\ERP\Accounting\Calc::CALCULATION_PERCENTAGE: $calculation = QUI\ERP\Accounting\Calc::CALCULATION_PERCENTAGE; diff --git a/src/QUI/ERP/Discount/PriceFactor.php b/src/QUI/ERP/Discount/PriceFactor.php index c18cdb2bc519e1891f46b97ce27636445e3d91fe..12d57d88c919757ed92051840f75b4320a8a798b 100644 --- a/src/QUI/ERP/Discount/PriceFactor.php +++ b/src/QUI/ERP/Discount/PriceFactor.php @@ -47,7 +47,7 @@ public function getVatType(): QUI\ERP\Tax\TaxType return QUI\ERP\Tax\Utils::getShopTaxType(); } - $standardTax = explode(':', $this->vat); + $standardTax = explode(':', (string)$this->vat); if (!isset($standardTax[1])) { return QUI\ERP\Tax\Utils::getShopTaxType();