Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .phpstan.dist.baselines/argument.type.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions .phpstan.dist.baselines/booleanNot.exprNotBoolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions .phpstan.dist.baselines/foreach.nonIterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>|false supplied for foreach, only iterables are supported.',
'count' => 1,
Expand Down
5 changes: 0 additions & 5 deletions .phpstan.dist.baselines/function.strict.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions .phpstan.dist.baselines/if.condNotBoolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions .phpstan.dist.baselines/method.nonObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions .phpstan.dist.baselines/return.type.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions .phpstan.dist.baselines/variable.undefined.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
42 changes: 24 additions & 18 deletions app/code/core/Mage/Api2/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Comment on lines +56 to 60
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sreichel i'm pretty sure copilot is wrong there


$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;
}
Expand All @@ -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 [];
}
Comment on lines +84 to +88

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'];
}
}

Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Loading