From 13ed3e0f9c920f96d465417543b32bf3406170d0 Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 09:17:44 +0200 Subject: [PATCH 01/15] phpstan: checks around getConfig + asArray --- app/code/core/Mage/Api2/Helper/Data.php | 54 +++++++++++++-------- app/code/core/Mage/Payment/Helper/Data.php | 13 ++++- app/code/core/Mage/Payment/Model/Config.php | 12 ++++- lib/Varien/Data/Collection/Db.php | 4 +- lib/Varien/Image/Adapter/Gd2.php | 4 +- 5 files changed, 62 insertions(+), 25 deletions(-) diff --git a/app/code/core/Mage/Api2/Helper/Data.php b/app/code/core/Mage/Api2/Helper/Data.php index b0404ed7d46..0be56a6ef8d 100644 --- a/app/code/core/Mage/Api2/Helper/Data.php +++ b/app/code/core/Mage/Api2/Helper/Data.php @@ -53,25 +53,23 @@ protected static function _compareOrder($a, $b) */ public function getAuthAdapters($enabledOnly = false) { - $adapters = Mage::getConfig()->getNode(self::XML_PATH_AUTH_ADAPTERS); + $adapters = Mage::getConfig()?->getNode(self::XML_PATH_AUTH_ADAPTERS); - if (!$adapters) { + if (!$adapters instanceof Varien_Simplexml_Element) { return []; } $adapters = $adapters->asArray(); - if ($enabledOnly) { - foreach ($adapters as $adapter) { - if (empty($adapter['enabled'])) { - unset($adapters); - } - } + if (!is_array($adapters)) { + return []; + } - $adapters = (array) $adapters; + if ($enabledOnly) { + $adapters = array_filter($adapters, fn($adapter) => !empty($adapter['enabled'])); } - uasort($adapters, ['Mage_Api2_Helper_Data', '_compareOrder']); + uasort($adapters, self::_compareOrder(...)); return $adapters; } @@ -83,14 +81,22 @@ public function getAuthAdapters($enabledOnly = false) */ public function getUserTypes() { - $userModels = []; - $types = Mage::getConfig()->getNode(self::XML_PATH_USER_TYPES); + $types = Mage::getConfig()?->getNode(self::XML_PATH_USER_TYPES); + + if (!$types instanceof Varien_Simplexml_Element) { + return []; + } + + $types = $types->asArray(); - if ($types) { - foreach ($types->asArray() as $type => $params) { - if (!empty($params['allowed'])) { - $userModels[$type] = $params['model']; - } + if (!is_array($types)) { + return []; + } + + $userModels = []; + foreach ($types as $type => $params) { + if (!empty($params['allowed'])) { + $userModels[$type] = $params['model']; } } @@ -104,7 +110,12 @@ public function getUserTypes() */ public function getRequestInterpreterAdapters() { - return (array) Mage::app()->getConfig()->getNode(self::XML_PATH_API2_REQUEST_INTERPRETERS); + $node = Mage::app()->getConfig()->getNode(self::XML_PATH_API2_REQUEST_INTERPRETERS); + if (!$node instanceof Varien_Simplexml_Element) { + return []; + } + + return (array) $node; } /** @@ -114,7 +125,12 @@ public function getRequestInterpreterAdapters() */ public function getResponseRenderAdapters() { - return (array) Mage::app()->getConfig()->getNode(self::XML_PATH_API2_RESPONSE_RENDERS); + $node = Mage::app()->getConfig()->getNode(self::XML_PATH_API2_RESPONSE_RENDERS); + if (!$node instanceof Varien_Simplexml_Element) { + return []; + } + + return (array) $node; } /** diff --git a/app/code/core/Mage/Payment/Helper/Data.php b/app/code/core/Mage/Payment/Helper/Data.php index 3db90cf190b..ef95b92c381 100644 --- a/app/code/core/Mage/Payment/Helper/Data.php +++ b/app/code/core/Mage/Payment/Helper/Data.php @@ -242,7 +242,18 @@ public function getPaymentMethodList($sorted = true, $asLabelValue = false, $wit } if ($asLabelValue && $withGroups) { - $groups = Mage::app()->getConfig()->getNode(self::XML_PATH_PAYMENT_GROUPS)->asCanonicalArray(); + $groups = Mage::app()->getConfig()->getNode(self::XML_PATH_PAYMENT_GROUPS); + + if ($groups instanceof Varien_Simplexml_Element) { + $groups = $groups->asCanonicalArray(); + + if (!is_array($groups)) { + $groups = []; + } + } else { + $groups = []; + } + foreach ($groups as $code => $title) { $methods[$code] = $title; // for sorting, see below } diff --git a/app/code/core/Mage/Payment/Model/Config.php b/app/code/core/Mage/Payment/Model/Config.php index b98e29fe623..7c123bc3d99 100644 --- a/app/code/core/Mage/Payment/Model/Config.php +++ b/app/code/core/Mage/Payment/Model/Config.php @@ -98,7 +98,17 @@ protected function _getMethod($code, $config, $store = null) */ public function getCcTypes() { - $_types = Mage::getConfig()->getNode('global/payment/cc/types')->asArray(); + $_types = Mage::getConfig()->getNode('global/payment/cc/types'); + + if ($_types === false) { + return []; + } + + $_types = $_types->asArray(); + + if (is_string($_types)) { + return []; + } uasort($_types, ['Mage_Payment_Model_Config', 'compareCcTypes']); diff --git a/lib/Varien/Data/Collection/Db.php b/lib/Varien/Data/Collection/Db.php index 1579d7ccc86..46653a5b01a 100644 --- a/lib/Varien/Data/Collection/Db.php +++ b/lib/Varien/Data/Collection/Db.php @@ -66,7 +66,7 @@ class Varien_Data_Collection_Db extends Varien_Data_Collection /** * Fields map for correlation names & real selected fields * - * @var null|array{fields: array} + * @var null|array> */ protected $_map = null; @@ -899,7 +899,7 @@ public function addFilterToMap($filter, $alias, $group = 'fields') { if (is_null($this->_map)) { $this->_map = [$group => []]; - } elseif (is_null($this->_map[$group])) { + } elseif (!isset($this->_map[$group])) { $this->_map[$group] = []; } diff --git a/lib/Varien/Image/Adapter/Gd2.php b/lib/Varien/Image/Adapter/Gd2.php index 3372fd43f27..44629e0d720 100644 --- a/lib/Varien/Image/Adapter/Gd2.php +++ b/lib/Varien/Image/Adapter/Gd2.php @@ -130,11 +130,11 @@ public function save($destination = null, $newName = null) { if (isset($destination) && isset($newName)) { $fileName = $destination . '/' . $newName; - } elseif (isset($destination) && !isset($newName)) { + } elseif (isset($destination)) { $info = pathinfo($destination); $fileName = $destination; $destination = $info['dirname']; - } elseif (!isset($destination) && isset($newName)) { + } elseif (isset($newName)) { $fileName = $this->_fileSrcPath . '/' . $newName; } else { $fileName = $this->_fileSrcPath . $this->_fileSrcName; From bfed783874b0e78e93aeceb592d73194d2687f1d Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 09:26:16 +0200 Subject: [PATCH 02/15] ~ use <=> for compareCcTypes --- app/code/core/Mage/Payment/Model/Config.php | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/app/code/core/Mage/Payment/Model/Config.php b/app/code/core/Mage/Payment/Model/Config.php index 7c123bc3d99..d7f776f5ab1 100644 --- a/app/code/core/Mage/Payment/Model/Config.php +++ b/app/code/core/Mage/Payment/Model/Config.php @@ -110,7 +110,7 @@ public function getCcTypes() return []; } - uasort($_types, ['Mage_Payment_Model_Config', 'compareCcTypes']); + uasort($_types, self::compareCcTypes(...)); $types = []; foreach ($_types as $data) { @@ -165,22 +165,6 @@ public function getYears() */ public static function compareCcTypes($sortA, $sortB) { - if (!isset($sortA['order'])) { - $sortA['order'] = 0; - } - - if (!isset($sortB['order'])) { - $sortB['order'] = 0; - } - - if ($sortA['order'] == $sortB['order']) { - return 0; - } - - if ($sortA['order'] > $sortB['order']) { - return 1; - } - - return -1; + return ($sortA['order'] ?? 0) <=> ($sortB['order'] ?? 0); } } From abb7a7f24ea2e3396fbf158bbcc1b25d0d7e4b7a Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 10:05:03 +0200 Subject: [PATCH 03/15] ~ remove ignored errors and more patches --- .phpstan.dist.baselines/argument.type.php | 15 --------------- .phpstan.dist.baselines/assign.propertyType.php | 15 --------------- .../booleanNot.exprNotBoolean.php | 5 ----- .phpstan.dist.baselines/equal.notAllowed.php | 5 ----- .phpstan.dist.baselines/foreach.nonIterable.php | 5 ----- .phpstan.dist.baselines/function.strict.php | 5 ----- .phpstan.dist.baselines/if.condNotBoolean.php | 5 ----- .phpstan.dist.baselines/method.nonObject.php | 10 ---------- .phpstan.dist.baselines/return.type.php | 5 ----- .phpstan.dist.baselines/variable.undefined.php | 5 ----- app/code/core/Mage/Api2/Helper/Data.php | 2 +- .../Api2/Model/Resource/Acl/Filter/Attribute.php | 2 +- 12 files changed, 2 insertions(+), 77 deletions(-) diff --git a/.phpstan.dist.baselines/argument.type.php b/.phpstan.dist.baselines/argument.type.php index bc930b84ca9..99d1aace326 100644 --- a/.phpstan.dist.baselines/argument.type.php +++ b/.phpstan.dist.baselines/argument.type.php @@ -951,16 +951,6 @@ 'count' => 2, 'path' => __DIR__ . '/../app/code/core/Mage/Api/Model/Wsdl/Config/Element.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Parameter #1 $array of function uasort expects array, array|string given.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Api2/Helper/Data.php', -]; -$ignoreErrors[] = [ - 'rawMessage' => 'Parameter #2 $string of function explode expects string, string|true given.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Api2/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Parameter #1 $roleId of method Mage_Api2_Model_Acl::addRole() expects int, int|string|null given.', 'count' => 1, @@ -4896,11 +4886,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Parameter #1 $array of function uasort expects array, array|string given.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Model/Config.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Parameter #2 $array of function array_key_exists expects array, array|int given.', 'count' => 1, diff --git a/.phpstan.dist.baselines/assign.propertyType.php b/.phpstan.dist.baselines/assign.propertyType.php index 5e140fa8a59..2d9bcd53ee1 100644 --- a/.phpstan.dist.baselines/assign.propertyType.php +++ b/.phpstan.dist.baselines/assign.propertyType.php @@ -431,11 +431,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Index/Model/Resource/Lock/Resource.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Property Varien_Data_Collection_Db::$_map (array{fields: array}|null) does not accept array{fields: non-empty-array}.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Newsletter/Model/Resource/Subscriber/Collection.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Property Mage_Page_Block_Html_Pager::$_frameEnd (int) does not accept float|int.', 'count' => 1, @@ -581,16 +576,6 @@ 'count' => 1, 'path' => __DIR__ . '/../lib/Mage/HTTP/Client/Socket.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Property Varien_Data_Collection_Db::$_map (array{fields: array}|null) does not accept non-empty-array>.', - 'count' => 2, - 'path' => __DIR__ . '/../lib/Varien/Data/Collection/Db.php', -]; -$ignoreErrors[] = [ - 'rawMessage' => 'Property Varien_Data_Collection_Db::$_map (array{fields: array}|null) does not accept non-empty-array.', - 'count' => 1, - 'path' => __DIR__ . '/../lib/Varien/Data/Collection/Db.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Property Varien_Data_Form_Filter_Date::$_locale (string|Zend_Locale) does not accept string|Zend_Locale|null.', 'count' => 1, diff --git a/.phpstan.dist.baselines/booleanNot.exprNotBoolean.php b/.phpstan.dist.baselines/booleanNot.exprNotBoolean.php index 3f04f86addb..0977686bf4f 100644 --- a/.phpstan.dist.baselines/booleanNot.exprNotBoolean.php +++ b/.phpstan.dist.baselines/booleanNot.exprNotBoolean.php @@ -1111,11 +1111,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Api/Model/Wsdl/Config/Element.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Only booleans are allowed in a negated boolean, Mage_Core_Model_Config_Element|false given.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Api2/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Only booleans are allowed in a negated boolean, array given.', 'count' => 1, diff --git a/.phpstan.dist.baselines/equal.notAllowed.php b/.phpstan.dist.baselines/equal.notAllowed.php index dabfcf1dfaf..651a03adf20 100644 --- a/.phpstan.dist.baselines/equal.notAllowed.php +++ b/.phpstan.dist.baselines/equal.notAllowed.php @@ -4361,11 +4361,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Block/Info/Container.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Loose comparison via "==" between mixed and mixed is not allowed.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Model/Config.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Loose comparison via "==" between mixed and int is not allowed.', 'count' => 1, diff --git a/.phpstan.dist.baselines/foreach.nonIterable.php b/.phpstan.dist.baselines/foreach.nonIterable.php index 4e240a0e480..ae5aed2efd2 100644 --- a/.phpstan.dist.baselines/foreach.nonIterable.php +++ b/.phpstan.dist.baselines/foreach.nonIterable.php @@ -96,11 +96,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Api/Model/Resource/User.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Argument of an invalid type array|string supplied for foreach, only iterables are supported.', - 'count' => 2, - 'path' => __DIR__ . '/../app/code/core/Mage/Api2/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Argument of an invalid type list|false supplied for foreach, only iterables are supported.', 'count' => 1, diff --git a/.phpstan.dist.baselines/function.strict.php b/.phpstan.dist.baselines/function.strict.php index ee1b3c51959..05bd3efe0c7 100644 --- a/.phpstan.dist.baselines/function.strict.php +++ b/.phpstan.dist.baselines/function.strict.php @@ -311,11 +311,6 @@ 'count' => 2, 'path' => __DIR__ . '/../app/code/core/Mage/Api/Model/Wsdl/Config/Base.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Call to function in_array() requires parameter #3 to be set.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Api2/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Call to function in_array() requires parameter #3 to be set.', 'count' => 1, diff --git a/.phpstan.dist.baselines/if.condNotBoolean.php b/.phpstan.dist.baselines/if.condNotBoolean.php index d0010742a10..5ecfa9830e5 100644 --- a/.phpstan.dist.baselines/if.condNotBoolean.php +++ b/.phpstan.dist.baselines/if.condNotBoolean.php @@ -2121,11 +2121,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Api2/Block/Adminhtml/Permissions/User/Edit/Tab/Roles.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Only booleans are allowed in an if condition, Mage_Core_Model_Config_Element|false given.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Api2/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Only booleans are allowed in an if condition, array given.', 'count' => 1, diff --git a/.phpstan.dist.baselines/method.nonObject.php b/.phpstan.dist.baselines/method.nonObject.php index 04ed310b7ff..05627869363 100644 --- a/.phpstan.dist.baselines/method.nonObject.php +++ b/.phpstan.dist.baselines/method.nonObject.php @@ -2001,11 +2001,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Api2/Block/Adminhtml/Roles/Tab/Users.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Cannot call method getNode() on Mage_Core_Model_Config|null.', - 'count' => 2, - 'path' => __DIR__ . '/../app/code/core/Mage/Api2/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Cannot call method children() on array|Varien_Simplexml_Element.', 'count' => 1, @@ -4896,11 +4891,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Block/Info/Container.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Cannot call method asCanonicalArray() on Mage_Core_Model_Config_Element|false.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Cannot call method getBlockClassName() on Mage_Core_Model_Config|null.', 'count' => 1, diff --git a/.phpstan.dist.baselines/return.type.php b/.phpstan.dist.baselines/return.type.php index f68913cdf90..b1478d61e93 100644 --- a/.phpstan.dist.baselines/return.type.php +++ b/.phpstan.dist.baselines/return.type.php @@ -431,11 +431,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Api/Model/User.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Method Mage_Api2_Helper_Data::getAuthAdapters() should return array but returns array|string.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Api2/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Method Mage_Api2_Model_Config::getResourceAttributes() should return array but returns array|string.', 'count' => 1, diff --git a/.phpstan.dist.baselines/variable.undefined.php b/.phpstan.dist.baselines/variable.undefined.php index 71a65a78611..0b5545ed0f5 100644 --- a/.phpstan.dist.baselines/variable.undefined.php +++ b/.phpstan.dist.baselines/variable.undefined.php @@ -6,11 +6,6 @@ 'count' => 2, 'path' => __DIR__ . '/../app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Variable $adapters might not be defined.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Api2/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Variable $operationName might not be defined.', 'count' => 2, diff --git a/app/code/core/Mage/Api2/Helper/Data.php b/app/code/core/Mage/Api2/Helper/Data.php index 0be56a6ef8d..9103a2f6db2 100644 --- a/app/code/core/Mage/Api2/Helper/Data.php +++ b/app/code/core/Mage/Api2/Helper/Data.php @@ -141,7 +141,7 @@ public function getResponseRenderAdapters() */ public function isApiTypeSupported($type) { - return in_array($type, Mage_Api2_Model_Server::getApiTypes()); + return in_array($type, Mage_Api2_Model_Server::getApiTypes(), true); } /** diff --git a/app/code/core/Mage/Api2/Model/Resource/Acl/Filter/Attribute.php b/app/code/core/Mage/Api2/Model/Resource/Acl/Filter/Attribute.php index b0b3de73f5f..3c2d67e249f 100644 --- a/app/code/core/Mage/Api2/Model/Resource/Acl/Filter/Attribute.php +++ b/app/code/core/Mage/Api2/Model/Resource/Acl/Filter/Attribute.php @@ -31,7 +31,7 @@ protected function _construct() * @param string $userType * @param string $resourceId * @param Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_* $operation - * @return null|bool|string + * @return false|null|string */ public function getAllowedAttributes($userType, $resourceId, $operation) { From 0696384a99e2b18832bf51104d5c3d8cca703de0 Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 10:08:27 +0200 Subject: [PATCH 04/15] is_string to !is_array --- app/code/core/Mage/Payment/Model/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/Payment/Model/Config.php b/app/code/core/Mage/Payment/Model/Config.php index d7f776f5ab1..6e6fae9c7a9 100644 --- a/app/code/core/Mage/Payment/Model/Config.php +++ b/app/code/core/Mage/Payment/Model/Config.php @@ -106,7 +106,7 @@ public function getCcTypes() $_types = $_types->asArray(); - if (is_string($_types)) { + if (!is_array($_types)) { return []; } From 07531c37f06989668f4c10145347246b21c62a48 Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 10:15:43 +0200 Subject: [PATCH 05/15] ~ fixes --- .phpstan.dist.baselines/foreach.nonIterable.php | 10 ---------- .phpstan.dist.baselines/isset.variable.php | 10 ---------- .phpstan.dist.baselines/method.nonObject.php | 5 ----- .../Mage/Api2/Model/Resource/Acl/Filter/Attribute.php | 2 +- 4 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 .phpstan.dist.baselines/isset.variable.php diff --git a/.phpstan.dist.baselines/foreach.nonIterable.php b/.phpstan.dist.baselines/foreach.nonIterable.php index ae5aed2efd2..1fffab91ce2 100644 --- a/.phpstan.dist.baselines/foreach.nonIterable.php +++ b/.phpstan.dist.baselines/foreach.nonIterable.php @@ -466,16 +466,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Block/Info.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Argument of an invalid type array|string supplied for foreach, only iterables are supported.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; -$ignoreErrors[] = [ - 'rawMessage' => 'Argument of an invalid type array|string supplied for foreach, only iterables are supported.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Model/Config.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Argument of an invalid type array|false|null supplied for foreach, only iterables are supported.', 'count' => 1, diff --git a/.phpstan.dist.baselines/isset.variable.php b/.phpstan.dist.baselines/isset.variable.php deleted file mode 100644 index 5d6dbb5f2f1..00000000000 --- a/.phpstan.dist.baselines/isset.variable.php +++ /dev/null @@ -1,10 +0,0 @@ - 'Variable $destination in isset() always exists and is always null.', - 'count' => 1, - 'path' => __DIR__ . '/../lib/Varien/Image/Adapter/Gd2.php', -]; - -return ['parameters' => ['ignoreErrors' => $ignoreErrors]]; diff --git a/.phpstan.dist.baselines/method.nonObject.php b/.phpstan.dist.baselines/method.nonObject.php index 05627869363..cd3c8615712 100644 --- a/.phpstan.dist.baselines/method.nonObject.php +++ b/.phpstan.dist.baselines/method.nonObject.php @@ -4906,11 +4906,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Cannot call method asArray() on Mage_Core_Model_Config_Element|false.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Model/Config.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Cannot call method getNode() on Mage_Core_Model_Config|null.', 'count' => 1, diff --git a/app/code/core/Mage/Api2/Model/Resource/Acl/Filter/Attribute.php b/app/code/core/Mage/Api2/Model/Resource/Acl/Filter/Attribute.php index 3c2d67e249f..514c32d7dab 100644 --- a/app/code/core/Mage/Api2/Model/Resource/Acl/Filter/Attribute.php +++ b/app/code/core/Mage/Api2/Model/Resource/Acl/Filter/Attribute.php @@ -31,7 +31,7 @@ protected function _construct() * @param string $userType * @param string $resourceId * @param Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_* $operation - * @return false|null|string + * @return null|false|string */ public function getAllowedAttributes($userType, $resourceId, $operation) { From 4ad429f052d5453f6f93b15a82fcab65bd7083e0 Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 10:17:00 +0200 Subject: [PATCH 06/15] instanceof check --- app/code/core/Mage/Payment/Model/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/Payment/Model/Config.php b/app/code/core/Mage/Payment/Model/Config.php index 6e6fae9c7a9..9196bf3b50a 100644 --- a/app/code/core/Mage/Payment/Model/Config.php +++ b/app/code/core/Mage/Payment/Model/Config.php @@ -100,7 +100,7 @@ public function getCcTypes() { $_types = Mage::getConfig()->getNode('global/payment/cc/types'); - if ($_types === false) { + if (!$_types instanceof Varien_Simplexml_Element) { return []; } From fca7c48c54844122a052ed3927a373d99db1e3c9 Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 10:20:38 +0200 Subject: [PATCH 07/15] ~ revert (array) $node cast --- .phpstan.dist.baselines/_loader.php | 1 - app/code/core/Mage/Api2/Helper/Data.php | 14 ++------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/.phpstan.dist.baselines/_loader.php b/.phpstan.dist.baselines/_loader.php index 3d14cefd84a..b59aec7395a 100644 --- a/.phpstan.dist.baselines/_loader.php +++ b/.phpstan.dist.baselines/_loader.php @@ -58,7 +58,6 @@ __DIR__ . '/if.alwaysTrue.php', __DIR__ . '/if.condNotBoolean.php', __DIR__ . '/instanceof.alwaysTrue.php', - __DIR__ . '/isset.variable.php', __DIR__ . '/method.childParameterType.php', __DIR__ . '/method.childReturnType.php', __DIR__ . '/method.deprecated.php', diff --git a/app/code/core/Mage/Api2/Helper/Data.php b/app/code/core/Mage/Api2/Helper/Data.php index 9103a2f6db2..ccc8822a766 100644 --- a/app/code/core/Mage/Api2/Helper/Data.php +++ b/app/code/core/Mage/Api2/Helper/Data.php @@ -110,12 +110,7 @@ public function getUserTypes() */ public function getRequestInterpreterAdapters() { - $node = Mage::app()->getConfig()->getNode(self::XML_PATH_API2_REQUEST_INTERPRETERS); - if (!$node instanceof Varien_Simplexml_Element) { - return []; - } - - return (array) $node; + return (array) Mage::app()->getConfig()->getNode(self::XML_PATH_API2_REQUEST_INTERPRETERS); } /** @@ -125,12 +120,7 @@ public function getRequestInterpreterAdapters() */ public function getResponseRenderAdapters() { - $node = Mage::app()->getConfig()->getNode(self::XML_PATH_API2_RESPONSE_RENDERS); - if (!$node instanceof Varien_Simplexml_Element) { - return []; - } - - return (array) $node; + return (array) Mage::app()->getConfig()->getNode(self::XML_PATH_API2_RESPONSE_RENDERS); } /** From 388d0a9eb149658e67187e9b0a7607f1d7fc8ddf Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 10:38:07 +0200 Subject: [PATCH 08/15] use array_key_exists for addFilterToMap --- lib/Varien/Data/Collection/Db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Varien/Data/Collection/Db.php b/lib/Varien/Data/Collection/Db.php index 46653a5b01a..5eea149cde4 100644 --- a/lib/Varien/Data/Collection/Db.php +++ b/lib/Varien/Data/Collection/Db.php @@ -899,7 +899,7 @@ public function addFilterToMap($filter, $alias, $group = 'fields') { if (is_null($this->_map)) { $this->_map = [$group => []]; - } elseif (!isset($this->_map[$group])) { + } elseif (!array_key_exists($group, $this->_map)) { $this->_map[$group] = []; } From 8a59644c43468667afb009c3d451c960950d33c7 Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 10:52:58 +0200 Subject: [PATCH 09/15] ~ more type hints --- .phpstan.dist.baselines/method.nonObject.php | 5 ----- .../missingType.iterableValue.php | 20 ------------------- .../missingType.property.php | 5 ----- app/code/core/Mage/Payment/Model/Config.php | 13 +++++++----- 4 files changed, 8 insertions(+), 35 deletions(-) diff --git a/.phpstan.dist.baselines/method.nonObject.php b/.phpstan.dist.baselines/method.nonObject.php index cd3c8615712..838adb41114 100644 --- a/.phpstan.dist.baselines/method.nonObject.php +++ b/.phpstan.dist.baselines/method.nonObject.php @@ -4906,11 +4906,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Cannot call method getNode() on Mage_Core_Model_Config|null.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Model/Config.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Cannot call method getCountryId() on Mage_Sales_Model_Order_Address|false.', 'count' => 1, diff --git a/.phpstan.dist.baselines/missingType.iterableValue.php b/.phpstan.dist.baselines/missingType.iterableValue.php index 87825bec716..3e67fa6116b 100644 --- a/.phpstan.dist.baselines/missingType.iterableValue.php +++ b/.phpstan.dist.baselines/missingType.iterableValue.php @@ -19226,26 +19226,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Model/Config.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Method Mage_Payment_Model_Config::getActiveMethods() return type has no value type specified in iterable type array.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Model/Config.php', -]; -$ignoreErrors[] = [ - 'rawMessage' => 'Method Mage_Payment_Model_Config::getAllMethods() return type has no value type specified in iterable type array.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Model/Config.php', -]; -$ignoreErrors[] = [ - 'rawMessage' => 'Method Mage_Payment_Model_Config::getMonths() return type has no value type specified in iterable type array.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Model/Config.php', -]; -$ignoreErrors[] = [ - 'rawMessage' => 'Method Mage_Payment_Model_Config::getYears() return type has no value type specified in iterable type array.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Model/Config.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Method Mage_Payment_Model_Info::setAdditionalInformation() has parameter $key with no value type specified in iterable type array.', 'count' => 1, diff --git a/.phpstan.dist.baselines/missingType.property.php b/.phpstan.dist.baselines/missingType.property.php index 2cd67b2f902..20431ec7357 100644 --- a/.phpstan.dist.baselines/missingType.property.php +++ b/.phpstan.dist.baselines/missingType.property.php @@ -2536,11 +2536,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Exception.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Property Mage_Payment_Model_Config::$_methods has no type specified.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Model/Config.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Property Mage_Payment_Model_Method_Abstract::$_canAuthorize has no type specified.', 'count' => 1, diff --git a/app/code/core/Mage/Payment/Model/Config.php b/app/code/core/Mage/Payment/Model/Config.php index 9196bf3b50a..3d408b832f5 100644 --- a/app/code/core/Mage/Payment/Model/Config.php +++ b/app/code/core/Mage/Payment/Model/Config.php @@ -18,13 +18,16 @@ */ class Mage_Payment_Model_Config { + /** + * @var array + */ protected static $_methods; /** * Retrieve active system payments * * @param ConfigStoreId $store - * @return array + * @return array */ public function getActiveMethods($store = null) { @@ -46,7 +49,7 @@ public function getActiveMethods($store = null) * Retrieve all system payments * * @param ConfigStoreId $store - * @return array + * @return array */ public function getAllMethods($store = null) { @@ -98,7 +101,7 @@ protected function _getMethod($code, $config, $store = null) */ public function getCcTypes() { - $_types = Mage::getConfig()->getNode('global/payment/cc/types'); + $_types = Mage::getConfig()?->getNode('global/payment/cc/types'); if (!$_types instanceof Varien_Simplexml_Element) { return []; @@ -125,7 +128,7 @@ public function getCcTypes() /** * Retrieve list of months translation * - * @return array + * @return array */ public function getMonths() { @@ -141,7 +144,7 @@ public function getMonths() /** * Retrieve array of available years * - * @return array + * @return array */ public function getYears() { From fab58e472dac1e01a9519f3fe4f29b98d90c6a05 Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 11:05:10 +0200 Subject: [PATCH 10/15] getActiveMethods: use _getMethod instead Mage::getModel --- app/code/core/Mage/Payment/Model/Config.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/core/Mage/Payment/Model/Config.php b/app/code/core/Mage/Payment/Model/Config.php index 3d408b832f5..4af2a8913d1 100644 --- a/app/code/core/Mage/Payment/Model/Config.php +++ b/app/code/core/Mage/Payment/Model/Config.php @@ -26,7 +26,7 @@ class Mage_Payment_Model_Config /** * Retrieve active system payments * - * @param ConfigStoreId $store + * @param ConfigStoreId $store * @return array */ public function getActiveMethods($store = null) @@ -35,9 +35,9 @@ public function getActiveMethods($store = null) $config = Mage::getStoreConfig('payment', $store); foreach ($config as $code => $methodConfig) { if (Mage::getStoreConfigFlag('payment/' . $code . '/active', $store) && array_key_exists('model', $methodConfig)) { - $methodModel = Mage::getModel($methodConfig['model']); + $methodModel = $this->_getMethod($code, $methodConfig); if ($methodModel && $methodModel->getConfigData('active', $store)) { - $methods[$code] = $this->_getMethod($code, $methodConfig); + $methods[$code] = $methodModel; } } } @@ -48,7 +48,7 @@ public function getActiveMethods($store = null) /** * Retrieve all system payments * - * @param ConfigStoreId $store + * @param ConfigStoreId $store * @return array */ public function getAllMethods($store = null) @@ -66,9 +66,9 @@ public function getAllMethods($store = null) } /** - * @param string $code - * @param array $config - * @param null|bool|int|Mage_Core_Model_Store|string $store $store + * @param string $code + * @param array $config + * @param ConfigStoreId $store * @return false|Mage_Payment_Model_Method_Abstract */ protected function _getMethod($code, $config, $store = null) From 402b83b2355e2fb1a5cea3c10d94987513ad24f1 Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 11:14:43 +0200 Subject: [PATCH 11/15] ~ phpstan fixes --- .phpstan.dist.baselines/booleanAnd.leftNotBoolean.php | 5 ----- .phpstan.dist.baselines/method.notFound.php | 5 ----- app/code/core/Mage/Payment/Model/Config.php | 2 +- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/.phpstan.dist.baselines/booleanAnd.leftNotBoolean.php b/.phpstan.dist.baselines/booleanAnd.leftNotBoolean.php index 501368db3a1..9b7f2ce25cc 100644 --- a/.phpstan.dist.baselines/booleanAnd.leftNotBoolean.php +++ b/.phpstan.dist.baselines/booleanAnd.leftNotBoolean.php @@ -1596,11 +1596,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Only booleans are allowed in &&, object|false given on the left side.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Model/Config.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Only booleans are allowed in &&, string|null given on the left side.', 'count' => 1, diff --git a/.phpstan.dist.baselines/method.notFound.php b/.phpstan.dist.baselines/method.notFound.php index b7df587f3e1..94897b5a5cb 100644 --- a/.phpstan.dist.baselines/method.notFound.php +++ b/.phpstan.dist.baselines/method.notFound.php @@ -1351,11 +1351,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Paygate/controllers/Authorizenet/PaymentController.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Call to an undefined method object::getConfigData().', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Model/Config.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Call to an undefined method object::setTemplate().', 'count' => 1, diff --git a/app/code/core/Mage/Payment/Model/Config.php b/app/code/core/Mage/Payment/Model/Config.php index 4af2a8913d1..7f405591a95 100644 --- a/app/code/core/Mage/Payment/Model/Config.php +++ b/app/code/core/Mage/Payment/Model/Config.php @@ -36,7 +36,7 @@ public function getActiveMethods($store = null) foreach ($config as $code => $methodConfig) { if (Mage::getStoreConfigFlag('payment/' . $code . '/active', $store) && array_key_exists('model', $methodConfig)) { $methodModel = $this->_getMethod($code, $methodConfig); - if ($methodModel && $methodModel->getConfigData('active', $store)) { + if ($methodModel !== false && (int) $methodModel->getConfigData('active', $store)) { $methods[$code] = $methodModel; } } From 5ddd306a62df0b2e6641626a6a28bc88e6506beb Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 11:32:02 +0200 Subject: [PATCH 12/15] add cast (bool) (int) --- app/code/core/Mage/Payment/Model/Config.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/code/core/Mage/Payment/Model/Config.php b/app/code/core/Mage/Payment/Model/Config.php index 7f405591a95..5081d32c6a6 100644 --- a/app/code/core/Mage/Payment/Model/Config.php +++ b/app/code/core/Mage/Payment/Model/Config.php @@ -35,8 +35,8 @@ public function getActiveMethods($store = null) $config = Mage::getStoreConfig('payment', $store); foreach ($config as $code => $methodConfig) { if (Mage::getStoreConfigFlag('payment/' . $code . '/active', $store) && array_key_exists('model', $methodConfig)) { - $methodModel = $this->_getMethod($code, $methodConfig); - if ($methodModel !== false && (int) $methodModel->getConfigData('active', $store)) { + $methodModel = $this->_getMethod($code, $methodConfig, $store); + if ($methodModel !== false && (bool) (int) $methodModel->getConfigData('active', $store)) { $methods[$code] = $methodModel; } } @@ -56,7 +56,7 @@ public function getAllMethods($store = null) $methods = []; $config = Mage::getStoreConfig('payment', $store); foreach ($config as $code => $methodConfig) { - $data = $this->_getMethod($code, $methodConfig); + $data = $this->_getMethod($code, $methodConfig, $store); if ($data !== false) { $methods[$code] = $data; } @@ -74,6 +74,7 @@ public function getAllMethods($store = null) protected function _getMethod($code, $config, $store = null) { if (isset(self::$_methods[$code])) { + self::$_methods[$code]->setStore($store); return self::$_methods[$code]; } From c961598f0ac18b9de813940d76e8adc970fddd19 Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 13:45:59 +0200 Subject: [PATCH 13/15] phpstan: more cleanup in Mage_Payment --- .phpstan.dist.baselines/argument.type.php | 5 -- .../booleanAnd.leftNotBoolean.php | 5 -- .phpstan.dist.baselines/function.strict.php | 5 -- .phpstan.dist.baselines/method.nonObject.php | 15 ----- .../missingType.iterableValue.php | 5 -- .../missingType.parameter.php | 5 -- .phpstan.dist.baselines/property.notFound.php | 5 -- .phpstan.dist.baselines/return.type.php | 5 -- app/code/core/Mage/Payment/Block/Form.php | 2 + app/code/core/Mage/Payment/Block/Info.php | 3 +- app/code/core/Mage/Payment/Helper/Data.php | 55 ++++++++++--------- .../Mage/Payment/Model/Method/Abstract.php | 11 ++++ 12 files changed, 44 insertions(+), 77 deletions(-) diff --git a/.phpstan.dist.baselines/argument.type.php b/.phpstan.dist.baselines/argument.type.php index 99d1aace326..6ad9cc0aa55 100644 --- a/.phpstan.dist.baselines/argument.type.php +++ b/.phpstan.dist.baselines/argument.type.php @@ -4881,11 +4881,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Exception.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Parameter #2 $haystack of function in_array expects array, array|false given.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Parameter #2 $array of function array_key_exists expects array, array|int given.', 'count' => 1, diff --git a/.phpstan.dist.baselines/booleanAnd.leftNotBoolean.php b/.phpstan.dist.baselines/booleanAnd.leftNotBoolean.php index 9b7f2ce25cc..487b2d6a25d 100644 --- a/.phpstan.dist.baselines/booleanAnd.leftNotBoolean.php +++ b/.phpstan.dist.baselines/booleanAnd.leftNotBoolean.php @@ -1591,11 +1591,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Block/Info/Container.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Only booleans are allowed in &&, Mage_Payment_Model_Method_Abstract given on the left side.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Only booleans are allowed in &&, string|null given on the left side.', 'count' => 1, diff --git a/.phpstan.dist.baselines/function.strict.php b/.phpstan.dist.baselines/function.strict.php index 05bd3efe0c7..b92ffdaadd3 100644 --- a/.phpstan.dist.baselines/function.strict.php +++ b/.phpstan.dist.baselines/function.strict.php @@ -1211,11 +1211,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Paygate/Model/Authorizenet.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Call to function in_array() requires parameter #3 to be set.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Call to function in_array() requires parameter #3 to be set.', 'count' => 1, diff --git a/.phpstan.dist.baselines/method.nonObject.php b/.phpstan.dist.baselines/method.nonObject.php index 838adb41114..7be2cb4a844 100644 --- a/.phpstan.dist.baselines/method.nonObject.php +++ b/.phpstan.dist.baselines/method.nonObject.php @@ -4891,21 +4891,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Block/Info/Container.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Cannot call method getBlockClassName() on Mage_Core_Model_Config|null.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; -$ignoreErrors[] = [ - 'rawMessage' => 'Cannot call method getConfigData() on object|false.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; -$ignoreErrors[] = [ - 'rawMessage' => 'Cannot call method setMethod() on Mage_Core_Block_Abstract|false.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Cannot call method getCountryId() on Mage_Sales_Model_Order_Address|false.', 'count' => 1, diff --git a/.phpstan.dist.baselines/missingType.iterableValue.php b/.phpstan.dist.baselines/missingType.iterableValue.php index 3e67fa6116b..4e549204a60 100644 --- a/.phpstan.dist.baselines/missingType.iterableValue.php +++ b/.phpstan.dist.baselines/missingType.iterableValue.php @@ -19191,11 +19191,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Block/Info/Ccsave.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Method Mage_Payment_Helper_Data::getAllBillingAgreementMethods() return type has no value type specified in iterable type array.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Method Mage_Payment_Helper_Data::getPaymentMethodList() return type has no value type specified in iterable type array.', 'count' => 1, diff --git a/.phpstan.dist.baselines/missingType.parameter.php b/.phpstan.dist.baselines/missingType.parameter.php index 05f3a1e9c3e..1225dc83797 100644 --- a/.phpstan.dist.baselines/missingType.parameter.php +++ b/.phpstan.dist.baselines/missingType.parameter.php @@ -1196,11 +1196,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Paygate/Model/Authorizenet/Cards.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Method Mage_Payment_Helper_Data::getMethodModelClassName() has parameter $code with no type specified.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Method Mage_Paypal_Block_Adminhtml_System_Config_Fieldset_Global::getElementOriginalData() has parameter $key with no type specified.', 'count' => 1, diff --git a/.phpstan.dist.baselines/property.notFound.php b/.phpstan.dist.baselines/property.notFound.php index 483f4c1c942..d94a36b198b 100644 --- a/.phpstan.dist.baselines/property.notFound.php +++ b/.phpstan.dist.baselines/property.notFound.php @@ -31,11 +31,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Customer/Model/Customer.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Access to an undefined property object::$sort_order.', - 'count' => 2, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Access to an undefined property object::$Code.', 'count' => 3, diff --git a/.phpstan.dist.baselines/return.type.php b/.phpstan.dist.baselines/return.type.php index b1478d61e93..e947ffc40a7 100644 --- a/.phpstan.dist.baselines/return.type.php +++ b/.phpstan.dist.baselines/return.type.php @@ -2361,11 +2361,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Method Mage_Payment_Helper_Data::getMethodInstance() should return Mage_Payment_Model_Method_Abstract|false but returns object|false.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Method Mage_Payment_Model_Billing_AgreementAbstract::getPaymentMethodInstance() should return Mage_Payment_Model_Method_Abstract|null but returns Mage_Payment_Model_Method_Abstract|false.', 'count' => 1, diff --git a/app/code/core/Mage/Payment/Block/Form.php b/app/code/core/Mage/Payment/Block/Form.php index 6597ebed517..763faaf8a5e 100644 --- a/app/code/core/Mage/Payment/Block/Form.php +++ b/app/code/core/Mage/Payment/Block/Form.php @@ -11,6 +11,8 @@ * Payment method form base block * * @package Mage_Payment + * + * @method $this setMethod(Mage_Payment_Model_Method_Abstract $method) */ class Mage_Payment_Block_Form extends Mage_Core_Block_Template { diff --git a/app/code/core/Mage/Payment/Block/Info.php b/app/code/core/Mage/Payment/Block/Info.php index 29c181a34bf..33293eac04b 100644 --- a/app/code/core/Mage/Payment/Block/Info.php +++ b/app/code/core/Mage/Payment/Block/Info.php @@ -12,7 +12,8 @@ * * @package Mage_Payment * - * @method bool hasIsSecureMode() + * @method bool hasIsSecureMode() + * @method $this setInfo(Mage_Payment_Model_Info $info) */ class Mage_Payment_Block_Info extends Mage_Core_Block_Template { diff --git a/app/code/core/Mage/Payment/Helper/Data.php b/app/code/core/Mage/Payment/Helper/Data.php index ef95b92c381..f4a4a5743cc 100644 --- a/app/code/core/Mage/Payment/Helper/Data.php +++ b/app/code/core/Mage/Payment/Helper/Data.php @@ -25,13 +25,14 @@ class Mage_Payment_Helper_Data extends Mage_Core_Helper_Abstract /** * Retrieve the class name of the payment method's model * - * @param $code + * @param string $code + * @param ConfigStoreId $store * @return null|string */ - public function getMethodModelClassName($code) + public function getMethodModelClassName($code, $store = null) { $key = self::XML_PATH_PAYMENT_METHODS . '/' . $code . '/model'; - return Mage::getStoreConfig($key); + return Mage::getStoreConfig($key, $store); } /** @@ -65,14 +66,14 @@ public function getStoreMethods($store = null, $quote = null) { $res = []; foreach (array_keys($this->getPaymentMethods($store)) as $code) { - $prefix = self::XML_PATH_PAYMENT_METHODS . '/' . $code . '/'; - if (!$model = Mage::getStoreConfig($prefix . 'model', $store)) { + $model = $this->getMethodModelClassName($code, $store); + if (!is_string($model)) { continue; } /** @var false|Mage_Payment_Model_Method_Abstract $methodInstance */ $methodInstance = Mage::getModel($model); - if (!$methodInstance) { + if (!$methodInstance instanceof Mage_Payment_Model_Method_Abstract) { continue; } @@ -82,8 +83,6 @@ public function getStoreMethods($store = null, $quote = null) continue; } - $sortOrder = (int) $methodInstance->getConfigData('sort_order', $store); - $methodInstance->setSortOrder($sortOrder); $res[] = $methodInstance; } @@ -92,14 +91,14 @@ public function getStoreMethods($store = null, $quote = null) } /** - * @param object $a - * @param object $b + * @param Mage_Payment_Model_Method_Abstract $a + * @param Mage_Payment_Model_Method_Abstract $b * @return int */ protected function _sortMethods($a, $b) { if (is_object($a)) { - return (int) $a->sort_order <=> (int) $b->sort_order; + return $a->getSortOrder() <=> $b->getSortOrder(); } return 0; @@ -108,24 +107,26 @@ protected function _sortMethods($a, $b) /** * Retrieve payment method form html * - * @return Mage_Core_Block_Abstract|Mage_Payment_Block_Form + * @return Mage_Payment_Block_Form */ public function getMethodFormBlock(Mage_Payment_Model_Method_Abstract $method) { - $block = false; $blockType = $method->getFormBlockType(); if ($this->getLayout()) { $block = $this->getLayout()->createBlock($blockType); - $block->setMethod($method); + } else { + $className = Mage::app()->getConfig()->getBlockClassName($blockType); + $block = new $className(); } - + /** @var Mage_Payment_Block_Form $block */ + $block->setMethod($method); return $block; } /** * Retrieve payment information block * - * @return Mage_Core_Block_Abstract + * @return Mage_Payment_Block_Info * @throws Mage_Core_Exception */ public function getInfoBlock(Mage_Payment_Model_Info $info) @@ -134,11 +135,11 @@ public function getInfoBlock(Mage_Payment_Model_Info $info) if ($this->getLayout()) { $block = $this->getLayout()->createBlock($blockType); } else { - $className = Mage::getConfig()->getBlockClassName($blockType); + $className = Mage::app()->getConfig()->getBlockClassName($blockType); $block = new $className(); } - /** @var Mage_Core_Block_Abstract $block */ + /** @var Mage_Payment_Block_Info $block */ $block->setInfo($info); return $block; } @@ -172,14 +173,14 @@ public function getRecurringProfileMethods($store = null) { $result = []; foreach (array_keys($this->getPaymentMethods($store)) as $code) { - $paymentMethodModelClassName = $this->getMethodModelClassName($code); - if (!$paymentMethodModelClassName) { + $paymentMethodModelClassName = $this->getMethodModelClassName($code, $store); + if (!is_string($paymentMethodModelClassName)) { continue; } /** @var Mage_Payment_Model_Method_Abstract $method */ $method = Mage::getModel($paymentMethodModelClassName); - if ($method && $method->canManageRecurringProfiles()) { + if ($method instanceof Mage_Payment_Model_Method_Abstract && $method->canManageRecurringProfiles()) { $result[] = $method; } } @@ -231,8 +232,11 @@ public function getPaymentMethodList($sorted = true, $asLabelValue = false, $wit $methods[$code] = $data['title']; } else { $paymentMethodModelClassName = $this->getMethodModelClassName($code); - if ($paymentMethodModelClassName) { - $methods[$code] = Mage::getModel($paymentMethodModelClassName)->getConfigData('title', $store); + if (is_string($paymentMethodModelClassName)) { + $methodModel = Mage::getModel($paymentMethodModelClassName); + if ($methodModel instanceof Mage_Payment_Model_Method_Abstract) { + $methods[$code] = $methodModel->getConfigData('title', $store); + } } } @@ -289,19 +293,18 @@ public function getPaymentMethodList($sorted = true, $asLabelValue = false, $wit /** * Retrieve all billing agreement methods (code and label) * - * @return array + * @return array */ public function getAllBillingAgreementMethods() { $result = []; - $interface = 'Mage_Payment_Model_Billing_Agreement_MethodInterface'; foreach ($this->getPaymentMethods() as $code => $data) { if (!isset($data['model'])) { continue; } $method = Mage::app()->getConfig()->getModelClassName($data['model']); - if (in_array($interface, class_implements($method))) { + if (is_a($method, Mage_Payment_Model_Billing_Agreement_MethodInterface::class)) { $result[$code] = $data['title']; } } diff --git a/app/code/core/Mage/Payment/Model/Method/Abstract.php b/app/code/core/Mage/Payment/Model/Method/Abstract.php index a2a1b4bb658..a0178a935f8 100644 --- a/app/code/core/Mage/Payment/Model/Method/Abstract.php +++ b/app/code/core/Mage/Payment/Model/Method/Abstract.php @@ -805,4 +805,15 @@ public function debugData($debugData) { $this->_debug($debugData); } + + /** + * @return int + */ + public function getSortOrder() + { + if (!$this->hasData('sort_order')) { + $this->setData('sort_order', $this->getConfigData('sort_order')); + } + return $this->getDataByKey('sort_order'); + } } From 876d7297e151b37937595a7713fa8429d295e95f Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 14:02:07 +0200 Subject: [PATCH 14/15] ~ fix use is_a --- .../booleanNot.exprNotBoolean.php | 15 --------------- .phpstan.dist.baselines/if.condNotBoolean.php | 10 ---------- .phpstan.dist.baselines/return.type.php | 5 ----- app/code/core/Mage/Payment/Helper/Data.php | 12 ++++++++---- 4 files changed, 8 insertions(+), 34 deletions(-) diff --git a/.phpstan.dist.baselines/booleanNot.exprNotBoolean.php b/.phpstan.dist.baselines/booleanNot.exprNotBoolean.php index 0977686bf4f..6e742b142aa 100644 --- a/.phpstan.dist.baselines/booleanNot.exprNotBoolean.php +++ b/.phpstan.dist.baselines/booleanNot.exprNotBoolean.php @@ -5041,21 +5041,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Block/Info.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Only booleans are allowed in a negated boolean, Mage_Payment_Model_Method_Abstract|false given.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; -$ignoreErrors[] = [ - 'rawMessage' => 'Only booleans are allowed in a negated boolean, mixed given.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; -$ignoreErrors[] = [ - 'rawMessage' => 'Only booleans are allowed in a negated boolean, string|null given.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Only booleans are allowed in a negated boolean, string given.', 'count' => 1, diff --git a/.phpstan.dist.baselines/if.condNotBoolean.php b/.phpstan.dist.baselines/if.condNotBoolean.php index 5ecfa9830e5..44af555c33c 100644 --- a/.phpstan.dist.baselines/if.condNotBoolean.php +++ b/.phpstan.dist.baselines/if.condNotBoolean.php @@ -6456,16 +6456,6 @@ 'count' => 2, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Block/Info/Container.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Only booleans are allowed in an if condition, Mage_Core_Model_Layout given.', - 'count' => 2, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; -$ignoreErrors[] = [ - 'rawMessage' => 'Only booleans are allowed in an if condition, string|null given.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Only booleans are allowed in an if condition, Mage_Payment_Model_Method_Abstract|false given.', 'count' => 1, diff --git a/.phpstan.dist.baselines/return.type.php b/.phpstan.dist.baselines/return.type.php index e947ffc40a7..15ba04b727b 100644 --- a/.phpstan.dist.baselines/return.type.php +++ b/.phpstan.dist.baselines/return.type.php @@ -2356,11 +2356,6 @@ 'count' => 1, 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Block/Form.php', ]; -$ignoreErrors[] = [ - 'rawMessage' => 'Method Mage_Payment_Helper_Data::getMethodFormBlock() should return Mage_Core_Block_Abstract but returns Mage_Core_Block_Abstract|false.', - 'count' => 1, - 'path' => __DIR__ . '/../app/code/core/Mage/Payment/Helper/Data.php', -]; $ignoreErrors[] = [ 'rawMessage' => 'Method Mage_Payment_Model_Billing_AgreementAbstract::getPaymentMethodInstance() should return Mage_Payment_Model_Method_Abstract|null but returns Mage_Payment_Model_Method_Abstract|false.', 'count' => 1, diff --git a/app/code/core/Mage/Payment/Helper/Data.php b/app/code/core/Mage/Payment/Helper/Data.php index f4a4a5743cc..7d15d37bf47 100644 --- a/app/code/core/Mage/Payment/Helper/Data.php +++ b/app/code/core/Mage/Payment/Helper/Data.php @@ -49,7 +49,11 @@ public function getMethodInstance($code) return false; } - return Mage::getModel($class); + /** + * @var false|Mage_Payment_Model_Method_Abstract $model + */ + $model = Mage::getModel($class); + return $model; } /** @@ -112,7 +116,7 @@ protected function _sortMethods($a, $b) public function getMethodFormBlock(Mage_Payment_Model_Method_Abstract $method) { $blockType = $method->getFormBlockType(); - if ($this->getLayout()) { + if ($this->getLayout() !== null) { $block = $this->getLayout()->createBlock($blockType); } else { $className = Mage::app()->getConfig()->getBlockClassName($blockType); @@ -132,7 +136,7 @@ public function getMethodFormBlock(Mage_Payment_Model_Method_Abstract $method) public function getInfoBlock(Mage_Payment_Model_Info $info) { $blockType = $info->getMethodInstance()->getInfoBlockType(); - if ($this->getLayout()) { + if ($this->getLayout() !== null) { $block = $this->getLayout()->createBlock($blockType); } else { $className = Mage::app()->getConfig()->getBlockClassName($blockType); @@ -304,7 +308,7 @@ public function getAllBillingAgreementMethods() } $method = Mage::app()->getConfig()->getModelClassName($data['model']); - if (is_a($method, Mage_Payment_Model_Billing_Agreement_MethodInterface::class)) { + if (is_a($method, Mage_Payment_Model_Billing_Agreement_MethodInterface::class, true)) { $result[$code] = $data['title']; } } From 14d24a9b15e5e755a7591b28239480e2706cd023 Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Fri, 22 May 2026 14:19:13 +0200 Subject: [PATCH 15/15] ~ rector --- app/code/core/Mage/Payment/Model/Method/Abstract.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/core/Mage/Payment/Model/Method/Abstract.php b/app/code/core/Mage/Payment/Model/Method/Abstract.php index a0178a935f8..42838917dce 100644 --- a/app/code/core/Mage/Payment/Model/Method/Abstract.php +++ b/app/code/core/Mage/Payment/Model/Method/Abstract.php @@ -814,6 +814,7 @@ public function getSortOrder() if (!$this->hasData('sort_order')) { $this->setData('sort_order', $this->getConfigData('sort_order')); } + return $this->getDataByKey('sort_order'); } }