diff --git a/.phpstan.dist.baselines/argument.type.php b/.phpstan.dist.baselines/argument.type.php index bc930b84ca9..978d1928811 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, 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/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..05bacb6f8f9 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, 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 b0404ed7d46..ccc8822a766 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 []; + } - if ($types) { - foreach ($types->asArray() as $type => $params) { - if (!empty($params['allowed'])) { - $userModels[$type] = $params['model']; - } + $types = $types->asArray(); + + if (!is_array($types)) { + return []; + } + + $userModels = []; + foreach ($types as $type => $params) { + if (!empty($params['allowed'])) { + $userModels[$type] = $params['model']; } } @@ -125,7 +131,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..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 null|bool|string + * @return null|false|string */ public function getAllowedAttributes($userType, $resourceId, $operation) {