Skip to content
Code-Schnipsel Gruppen Projekte
Commit 6100708f erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

fix(phpstan): improved method validity checks and reduced error handling

This commit fixes several issues in different PHP files.
- Added `method_exists` checks for `isActive` method in `activate.php`, `deactivate.php` and
`toggle.php` to prevent calls to an undefined method.
- Similar check added for `getTitle` method in `get.php`.
- Fixed sorting functionality in `search.php` by using `strcmp` instead of greater than comparison.
- Removed a large number of ignored errors in `phpstan-baseline.neon`, indicating reduced error
handling.
- Corrected the `implode` parameters order in `Discount.php` and typecasted variable to string
before using `explode` in `PriceFactor.php`.
- Updated `getTitle` & `toPriceFactor` method parameters in `Discount.php` to use union types for
compatibility with different data types.

Related: #18
Übergeordneter 000c2bb1
No related branches found
No related tags found
2 Merge Requests!13Update 'next-3.x' with latest changes from 'main',!12fix(phpstan): improved method validity checks and reduced error handling
Pipeline #15001 mit Warnungen bestanden mit Phase
in 2 Minuten und 15 Sekunden
......@@ -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'
......
......@@ -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'
......
......@@ -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;
},
......
......@@ -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;
......
......@@ -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 {
......
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
......@@ -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;
......
......@@ -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();
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren