From 894682e7d6e69bf50eb2738dff62fc6e11c5f25c Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Sun, 2 Nov 2025 08:15:48 +0100 Subject: [PATCH 1/2] phpcs-fixer: `ordered_types` - see https://cs.symfony.com/doc/rules/class_notation/ordered_types.html --- .php-cs-fixer.dist.php | 6 ++++++ app/code/core/Mage/Admin/Model/Resource/User.php | 2 +- app/code/core/Mage/Api/Model/Server/Adapter/Soap.php | 2 +- app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php | 2 +- app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php | 2 +- app/code/core/Mage/Catalog/Model/Category/Api.php | 2 +- tests/unit/Base/DefaultConfigTest.php | 2 +- tests/unit/Mage/Admin/Model/BlockTest.php | 2 +- tests/unit/Mage/Admin/Model/VariableTest.php | 2 +- tests/unit/Mage/AdminNotification/Model/InboxTest.php | 2 +- .../unit/Mage/Catalog/Model/Resource/Eav/AttributeTest.php | 2 +- tests/unit/Mage/Cms/Block/Widget/Page/LinkTest.php | 2 +- tests/unit/Mage/Core/Helper/DataTest.php | 2 +- tests/unit/Mage/Core/Model/AppTest.php | 6 +++--- tests/unit/Mage/GiftMessage/Helper/MessageTest.php | 2 +- tests/unit/Mage/Rule/Model/AbstractTest.php | 4 ++-- 16 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 90eaa46b857..b9d5516afa3 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -18,6 +18,8 @@ 'nullable_type_declaration_for_default_null_value' => true, // Operators - when multiline - must always be at the beginning or at the end of the line. 'operator_linebreak' => true, + // Sort union types and intersection types using configured order. + 'ordered_types' => true, // Calls to PHPUnit\Framework\TestCase static methods must all be of the same type, either $this->, self:: or static:: 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'], // PHPDoc annotation descriptions should not be a sentence. @@ -44,12 +46,16 @@ 'phpdoc_var_annotation_correct_order' => true, // @var and @type annotations of classy properties should not contain the name. 'phpdoc_var_without_name' => true, + // There MUST NOT be more than one property or constant declared per statement. + 'single_class_element_per_statement' => true, // Convert double quotes to single quotes for simple strings. 'single_quote' => true, // Arguments lists, array destructuring lists, arrays that are multi-line, match-lines and parameters lists must have a trailing comma. // removed "match" and "parameters" for PHP7 // see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/8308 'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays']], + // A single space or none should be around union type and intersection type operators. + 'types_spaces' => true, ]) ->setFinder( PhpCsFixer\Finder::create() diff --git a/app/code/core/Mage/Admin/Model/Resource/User.php b/app/code/core/Mage/Admin/Model/Resource/User.php index abe820ee2e9..576acbe1521 100644 --- a/app/code/core/Mage/Admin/Model/Resource/User.php +++ b/app/code/core/Mage/Admin/Model/Resource/User.php @@ -232,7 +232,7 @@ public function _saveRelations(Mage_Core_Model_Abstract $user) } $adapter->commit(); - } catch (Mage_Core_Exception|Exception $e) { + } catch (Exception|Mage_Core_Exception $e) { $adapter->rollBack(); throw $e; } diff --git a/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php b/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php index 12fe0e30cff..2f13de8096c 100644 --- a/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php +++ b/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php @@ -153,7 +153,7 @@ public function run() $this->_soap->handle(), ), ); - } catch (Zend_Soap_Server_Exception|Exception $e) { + } catch (Exception|Zend_Soap_Server_Exception $e) { $this->fault($e->getCode(), $e->getMessage()); } } diff --git a/app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php b/app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php index 5617750bd56..1adcccfcf67 100644 --- a/app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php +++ b/app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php @@ -66,7 +66,7 @@ public function run() ->setHeader('Content-Type', 'text/xml; charset=' . $apiConfigCharset) ->setHeader('Content-Length', strlen($content), true) ->setBody($content); - } catch (Zend_Soap_Server_Exception|Exception $e) { + } catch (Exception|Zend_Soap_Server_Exception $e) { $this->fault($e->getCode(), $e->getMessage()); } } diff --git a/app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php b/app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php index 1df7e61314b..885acce786c 100644 --- a/app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php +++ b/app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php @@ -87,7 +87,7 @@ public function run() ->setHeader('Content-Type', 'text/xml; charset=' . $apiConfigCharset) ->setHeader('Content-Length', strlen($content), true) ->setBody($content); - } catch (Zend_Soap_Server_Exception|Exception $e) { + } catch (Exception|Zend_Soap_Server_Exception $e) { $this->fault($e->getCode(), $e->getMessage()); } } diff --git a/app/code/core/Mage/Catalog/Model/Category/Api.php b/app/code/core/Mage/Catalog/Model/Category/Api.php index 6a02a9b617f..de9a2ae4335 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Api.php +++ b/app/code/core/Mage/Catalog/Model/Category/Api.php @@ -274,7 +274,7 @@ public function create($parentId, $categoryData, $store = null) } $category->save(); - } catch (Mage_Core_Exception|Exception $e) { + } catch (Exception|Mage_Core_Exception $e) { $this->_fault('data_invalid', $e->getMessage()); } diff --git a/tests/unit/Base/DefaultConfigTest.php b/tests/unit/Base/DefaultConfigTest.php index 41dcc2f2c00..63234319965 100644 --- a/tests/unit/Base/DefaultConfigTest.php +++ b/tests/unit/Base/DefaultConfigTest.php @@ -22,7 +22,7 @@ final class DefaultConfigTest extends TestCase /** * @dataProvider provideGetStoreConfig */ - public function testGetStoreConfig(string $expectedResult, string $path, bool|int|Mage_Core_Model_Store|null|string $store = null): void + public function testGetStoreConfig(string $expectedResult, string $path, null|bool|int|Mage_Core_Model_Store|string $store = null): void { self::assertSame($expectedResult, Mage::getStoreConfig($path, $store)); } diff --git a/tests/unit/Mage/Admin/Model/BlockTest.php b/tests/unit/Mage/Admin/Model/BlockTest.php index 2d667c2169d..a8c25833f81 100644 --- a/tests/unit/Mage/Admin/Model/BlockTest.php +++ b/tests/unit/Mage/Admin/Model/BlockTest.php @@ -36,7 +36,7 @@ public static function setUpBeforeClass(): void * @group Model * @throws Exception */ - public function testValidate(bool|array $expectedResult, array $methods): void + public function testValidate(array|bool $expectedResult, array $methods): void { $mock = $this->getMockWithCalledMethods(Subject::class, $methods); diff --git a/tests/unit/Mage/Admin/Model/VariableTest.php b/tests/unit/Mage/Admin/Model/VariableTest.php index 10a5d66cd59..7b5fa4b6948 100644 --- a/tests/unit/Mage/Admin/Model/VariableTest.php +++ b/tests/unit/Mage/Admin/Model/VariableTest.php @@ -34,7 +34,7 @@ public static function setUpBeforeClass(): void * @group Model * @throws Exception */ - public function testValidate(bool|array $expectedResult, array $methods): void + public function testValidate(array|bool $expectedResult, array $methods): void { $mock = $this->getMockWithCalledMethods(Subject::class, $methods); diff --git a/tests/unit/Mage/AdminNotification/Model/InboxTest.php b/tests/unit/Mage/AdminNotification/Model/InboxTest.php index 1e2315c1c12..653430a95d7 100644 --- a/tests/unit/Mage/AdminNotification/Model/InboxTest.php +++ b/tests/unit/Mage/AdminNotification/Model/InboxTest.php @@ -37,7 +37,7 @@ public static function setUpBeforeClass(): void * @dataProvider provideGetSeverities * @group Model */ - public function testGetSeverities(array|string|null $expectedResult, ?int $severity): void + public function testGetSeverities(null|array|string $expectedResult, ?int $severity): void { self::assertSame($expectedResult, self::$subject->getSeverities($severity)); } diff --git a/tests/unit/Mage/Catalog/Model/Resource/Eav/AttributeTest.php b/tests/unit/Mage/Catalog/Model/Resource/Eav/AttributeTest.php index 7806074122d..691c9413d60 100644 --- a/tests/unit/Mage/Catalog/Model/Resource/Eav/AttributeTest.php +++ b/tests/unit/Mage/Catalog/Model/Resource/Eav/AttributeTest.php @@ -30,7 +30,7 @@ public function setUp(): void * @dataProvider provideGetStoreId * @group Model */ - public function testGetStoreId(?int $expectedResult, int|string|null $withStoreId): void + public function testGetStoreId(?int $expectedResult, null|int|string $withStoreId): void { if ($withStoreId) { self::$subject->setStoreId($withStoreId); diff --git a/tests/unit/Mage/Cms/Block/Widget/Page/LinkTest.php b/tests/unit/Mage/Cms/Block/Widget/Page/LinkTest.php index de51eeab892..917698a12e2 100644 --- a/tests/unit/Mage/Cms/Block/Widget/Page/LinkTest.php +++ b/tests/unit/Mage/Cms/Block/Widget/Page/LinkTest.php @@ -60,7 +60,7 @@ public function testGetTitle(string $expectedResult, array $data): void * @group Block * @throws Mage_Core_Model_Store_Exception */ - public function testGetAnchorText(bool|string|null $expectedResult, array $data): void + public function testGetAnchorText(null|bool|string $expectedResult, array $data): void { self::$subject->setData($data); diff --git a/tests/unit/Mage/Core/Helper/DataTest.php b/tests/unit/Mage/Core/Helper/DataTest.php index 2a4989d454c..eb65c19e950 100644 --- a/tests/unit/Mage/Core/Helper/DataTest.php +++ b/tests/unit/Mage/Core/Helper/DataTest.php @@ -71,7 +71,7 @@ public function testValidateKey(): void */ public function testFormatTimezoneDate( string $expectedResult, - string|int|null $data, + null|int|string $data, string $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, bool $showTime = false, bool $useTimezone = false # disable timezone by default for tests diff --git a/tests/unit/Mage/Core/Model/AppTest.php b/tests/unit/Mage/Core/Model/AppTest.php index 4e0bacff41a..a0a78ea60ed 100644 --- a/tests/unit/Mage/Core/Model/AppTest.php +++ b/tests/unit/Mage/Core/Model/AppTest.php @@ -32,7 +32,7 @@ public static function setUpBeforeClass(): void * @dataProvider provideGetStore * @group Model */ - public function testGetStore(Mage_Core_Model_Store|int|string|bool|null $id): void + public function testGetStore(null|bool|int|Mage_Core_Model_Store|string $id): void { try { self::assertInstanceOf(Mage_Core_Model_Store::class, self::$subject->getStore($id)); @@ -47,7 +47,7 @@ public function testGetStore(Mage_Core_Model_Store|int|string|bool|null $id): vo * @dataProvider provideGetWebsite * @group Model */ - public function testGetWebsite(Mage_Core_Model_Website|int|string|bool|null $id): void + public function testGetWebsite(null|bool|int|Mage_Core_Model_Website|string $id): void { try { self::assertInstanceOf(Mage_Core_Model_Website::class, self::$subject->getWebsite($id)); @@ -62,7 +62,7 @@ public function testGetWebsite(Mage_Core_Model_Website|int|string|bool|null $id) * @dataProvider provideGetGroup * @group Model */ - public function testGetGroup(Mage_Core_Model_Store_Group|int|string|bool|null $id): void + public function testGetGroup(null|bool|int|Mage_Core_Model_Store_Group|string $id): void { try { self::assertInstanceOf(Mage_Core_Model_Store_Group::class, self::$subject->getGroup($id)); diff --git a/tests/unit/Mage/GiftMessage/Helper/MessageTest.php b/tests/unit/Mage/GiftMessage/Helper/MessageTest.php index b4e98b52b01..d77d74da3b7 100644 --- a/tests/unit/Mage/GiftMessage/Helper/MessageTest.php +++ b/tests/unit/Mage/GiftMessage/Helper/MessageTest.php @@ -35,7 +35,7 @@ public static function setUpBeforeClass(): void * * @group Helper */ - public function testIsMessagesAvailable(string $type, Varien_Object $entity, bool|int|Mage_Core_Model_Store|null|string $store = null): void + public function testIsMessagesAvailable(string $type, Varien_Object $entity, null|bool|int|Mage_Core_Model_Store|string $store = null): void { self::assertIsBool(self::$subject->isMessagesAvailable($type, $entity, $store)); } diff --git a/tests/unit/Mage/Rule/Model/AbstractTest.php b/tests/unit/Mage/Rule/Model/AbstractTest.php index 5936f4de8d8..614bae9f9a6 100644 --- a/tests/unit/Mage/Rule/Model/AbstractTest.php +++ b/tests/unit/Mage/Rule/Model/AbstractTest.php @@ -104,7 +104,7 @@ public function testLoadPost(array $data = []): void * @dataProvider provideValidateData * @group Model */ - public function testValidate(bool|array $expectedResul, ?array $data = null): void + public function testValidate(array|bool $expectedResul, ?array $data = null): void { $object = new Varien_Object($data); try { @@ -119,7 +119,7 @@ public function testValidate(bool|array $expectedResul, ?array $data = null): vo * @dataProvider provideValidateData * @group Model */ - public function testValidateData(bool|array $expectedResul, ?array $data = null): void + public function testValidateData(array|bool $expectedResul, ?array $data = null): void { if (PHP_VERSION_ID >= 80300 && version_compare(InstalledVersions::getPrettyVersion('shardj/zf1-future'), '1.24.2', '<=')) { self::markTestSkipped('see https://github.com/Shardj/zf1-future/pull/465'); From 1b33e54f7f21fb22535b0bd20d8a16dab63446fa Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Mon, 3 Nov 2025 18:46:06 +0100 Subject: [PATCH 2/2] exception --- app/code/core/Mage/Admin/Model/Resource/User.php | 9 +++++++-- app/code/core/Mage/Api/Model/Server/Adapter/Soap.php | 6 ++++-- app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php | 6 ++++-- app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php | 6 ++++-- app/code/core/Mage/Catalog/Model/Category/Api.php | 6 ++++-- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/code/core/Mage/Admin/Model/Resource/User.php b/app/code/core/Mage/Admin/Model/Resource/User.php index 576acbe1521..507dea94739 100644 --- a/app/code/core/Mage/Admin/Model/Resource/User.php +++ b/app/code/core/Mage/Admin/Model/Resource/User.php @@ -187,6 +187,8 @@ public function delete(Mage_Core_Model_Abstract $user) /** * TODO: unify _saveRelations() and add() methods, they make same things * + * @throws Mage_Core_Exception + * @throws Zend_Db_Adapter_Exception * @return $this|Mage_Core_Model_Abstract */ public function _saveRelations(Mage_Core_Model_Abstract $user) @@ -232,9 +234,12 @@ public function _saveRelations(Mage_Core_Model_Abstract $user) } $adapter->commit(); - } catch (Exception|Mage_Core_Exception $e) { + } catch (Mage_Core_Exception $mageCoreException) { $adapter->rollBack(); - throw $e; + throw $mageCoreException; + } catch (Exception $exception) { + $adapter->rollBack(); + throw $exception; } return $this; diff --git a/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php b/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php index 2f13de8096c..5d3ccef7c85 100644 --- a/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php +++ b/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php @@ -153,8 +153,10 @@ public function run() $this->_soap->handle(), ), ); - } catch (Exception|Zend_Soap_Server_Exception $e) { - $this->fault($e->getCode(), $e->getMessage()); + } catch (Zend_Soap_Server_Exception $zendSoapServerException) { + $this->fault($zendSoapServerException->getCode(), $zendSoapServerException->getMessage()); + } catch (Exception $exception) { + $this->fault($exception->getCode(), $exception->getMessage()); } } diff --git a/app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php b/app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php index 1adcccfcf67..23c430994ce 100644 --- a/app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php +++ b/app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php @@ -66,8 +66,10 @@ public function run() ->setHeader('Content-Type', 'text/xml; charset=' . $apiConfigCharset) ->setHeader('Content-Length', strlen($content), true) ->setBody($content); - } catch (Exception|Zend_Soap_Server_Exception $e) { - $this->fault($e->getCode(), $e->getMessage()); + } catch (Zend_Soap_Server_Exception $zendSoapServerException) { + $this->fault($zendSoapServerException->getCode(), $zendSoapServerException->getMessage()); + } catch (Exception $exception) { + $this->fault($exception->getCode(), $exception->getMessage()); } } diff --git a/app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php b/app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php index 885acce786c..0e38314805f 100644 --- a/app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php +++ b/app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php @@ -87,8 +87,10 @@ public function run() ->setHeader('Content-Type', 'text/xml; charset=' . $apiConfigCharset) ->setHeader('Content-Length', strlen($content), true) ->setBody($content); - } catch (Exception|Zend_Soap_Server_Exception $e) { - $this->fault($e->getCode(), $e->getMessage()); + } catch (Zend_Soap_Server_Exception $zendSoapServerException) { + $this->fault($zendSoapServerException->getCode(), $zendSoapServerException->getMessage()); + } catch (Exception $exception) { + $this->fault($exception->getCode(), $exception->getMessage()); } } diff --git a/app/code/core/Mage/Catalog/Model/Category/Api.php b/app/code/core/Mage/Catalog/Model/Category/Api.php index de9a2ae4335..9ae97e28208 100644 --- a/app/code/core/Mage/Catalog/Model/Category/Api.php +++ b/app/code/core/Mage/Catalog/Model/Category/Api.php @@ -274,8 +274,10 @@ public function create($parentId, $categoryData, $store = null) } $category->save(); - } catch (Exception|Mage_Core_Exception $e) { - $this->_fault('data_invalid', $e->getMessage()); + } catch (Mage_Core_Exception $mageCoreException) { + $this->_fault('data_invalid', $mageCoreException->getMessage()); + } catch (Exception $exception) { + $this->_fault('data_invalid', $exception->getMessage()); } return $category->getId();