From 3d7eaf63f2211a9e1a8defe8c29e8f6da889ab2e Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Mon, 22 Jul 2024 14:01:39 +0200 Subject: [PATCH 01/13] Rector: CQ - UnusedForeachValueToArrayKeysRector (#1) * Rector: CQ - UnusedForeachValueToArrayKeysRector See Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector * fixes + phpstan See fix at rector: https://github.com/rectorphp/rector-src/pull/6164 --- app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php | 4 ++-- app/code/core/Mage/Adminhtml/Block/Page/Menu.php | 2 +- app/code/core/Mage/Adminhtml/Block/Report/Grid.php | 2 +- .../Adminhtml/Block/Sales/Transactions/Child/Grid.php | 2 +- app/code/core/Mage/Adminhtml/Block/Store/Switcher.php | 4 ++-- app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php | 2 +- .../core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php | 2 +- app/code/core/Mage/Adminhtml/Block/Widget/Grid.php | 2 +- .../Block/Widget/Grid/Column/Renderer/Action.php | 2 +- app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php | 2 +- .../Adminhtml/Model/System/Config/Source/Admin/Page.php | 2 +- app/code/core/Mage/Api2/Model/Acl/Filter.php | 2 +- .../Model/Acl/Filter/Attribute/ResourcePermission.php | 2 +- app/code/core/Mage/Catalog/Model/Api2/Product.php | 2 +- app/code/core/Mage/Catalog/Model/Category.php | 2 +- app/code/core/Mage/Catalog/Model/Product/Type/Price.php | 2 +- .../core/Mage/Catalog/Model/Resource/Category/Flat.php | 2 +- app/code/core/Mage/Checkout/Model/Type/Onepage.php | 2 +- .../Mage/ConfigurableSwatches/Helper/Mediafallback.php | 2 +- app/code/core/Mage/Core/Helper/Data.php | 2 +- app/code/core/Mage/Core/Model/Cache.php | 2 +- app/code/core/Mage/Core/Model/Layout/Validator.php | 2 +- app/code/core/Mage/Core/Model/Locale.php | 2 +- app/code/core/Mage/Core/Model/Log/Adapter.php | 2 +- app/code/core/Mage/Core/Model/Url/Rewrite.php | 2 +- app/code/core/Mage/Core/Model/Url/Rewrite/Request.php | 2 +- app/code/core/Mage/Customer/Model/Address/Api.php | 8 ++++---- app/code/core/Mage/Customer/Model/Address/Api/V2.php | 6 +++--- app/code/core/Mage/Customer/Model/Customer/Api.php | 6 +++--- app/code/core/Mage/Dataflow/Model/Batch.php | 4 ++-- app/code/core/Mage/Dataflow/Model/Session/Parser/Csv.php | 2 +- app/code/core/Mage/Eav/Model/Entity/Abstract.php | 2 +- .../Mage/ImportExport/Model/Export/Entity/Product.php | 6 +++--- .../Mage/ImportExport/Model/Import/Entity/Customer.php | 2 +- .../Mage/ImportExport/Model/Import/Entity/Product.php | 2 +- app/code/core/Mage/Index/Model/Event.php | 2 +- app/code/core/Mage/Install/Block/Db/Main.php | 2 +- app/code/core/Mage/Install/Model/Installer/Console.php | 2 +- .../core/Mage/Install/Model/Installer/Db/Abstract.php | 2 +- app/code/core/Mage/Page/Block/Template/Links.php | 2 +- app/code/core/Mage/Paygate/Model/Authorizenet.php | 2 +- app/code/core/Mage/Payment/Block/Form/Cc.php | 2 +- app/code/core/Mage/Payment/Helper/Data.php | 6 +++--- .../core/Mage/Paypal/Model/Resource/Report/Settlement.php | 2 +- app/code/core/Mage/Reports/Model/Totals.php | 2 +- app/code/core/Mage/Rule/Model/Action/Abstract.php | 4 ++-- app/code/core/Mage/Rule/Model/Condition/Abstract.php | 6 +++--- app/code/core/Mage/Rule/Model/Condition/Combine.php | 2 +- .../Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php | 2 +- .../Mage/Sales/Model/Resource/Report/Order/Createdat.php | 2 +- .../core/Mage/Sales/Model/Resource/Sale/Collection.php | 2 +- .../sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php | 2 +- .../sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php | 2 +- app/code/core/Mage/Shipping/Model/Rate/Result.php | 2 +- app/code/core/Mage/Tag/Helper/Data.php | 2 +- app/code/core/Mage/Tag/controllers/IndexController.php | 2 +- .../core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php | 2 +- .../Catalog/Product/Attribute/Edit/AttributeForm.php | 2 +- .../Test/Block/Catalog/Product/Edit/Tab/Prices.php | 4 ++-- .../Adminhtml/Test/Block/Catalog/Product/ProductForm.php | 2 +- .../app/Mage/Adminhtml/Test/Block/Widget/FormTabs.php | 4 ++-- .../tests/app/Mage/Bundle/Test/Handler/Curl.php | 4 ++-- .../DeleteOptionsSubStep.php | 2 +- .../app/Mage/Customer/Test/Handler/Customer/Curl.php | 2 +- .../app/Mage/Weee/Test/Constraint/AssertFptApplied.php | 2 +- lib/Varien/Convert/Parser/Csv.php | 4 ++-- lib/Varien/Db/Statement/Pdo/Mysql.php | 2 +- lib/Varien/Http/Adapter/Curl.php | 2 +- lib/Varien/Object.php | 2 +- lib/Varien/Object/Cache.php | 2 +- phpstan.dist.baseline.neon | 5 ----- 71 files changed, 91 insertions(+), 96 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php index 700d3b3b17d..afc5f13938c 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php @@ -215,7 +215,7 @@ public function getChartUrl($directUrl = true) $dateStart->addMonth(1); break; } - foreach ($this->getAllSeries() as $index => $serie) { + foreach (array_keys($this->getAllSeries()) as $index) { if (in_array($d, $this->_axisLabels['x'])) { $datas[$index][] = (float)array_shift($this->_allSeries[$index]); } else { @@ -328,7 +328,7 @@ public function getChartUrl($directUrl = true) if (count($this->_axisLabels)) { $params['chxt'] = implode(',', array_keys($this->_axisLabels)); $indexid = 0; - foreach ($this->_axisLabels as $idx => $labels) { + foreach (array_keys($this->_axisLabels) as $idx) { if ($idx === 'x') { /** * Format date diff --git a/app/code/core/Mage/Adminhtml/Block/Page/Menu.php b/app/code/core/Mage/Adminhtml/Block/Page/Menu.php index d4872f9158d..20bb44f96f4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Page/Menu.php +++ b/app/code/core/Mage/Adminhtml/Block/Page/Menu.php @@ -164,7 +164,7 @@ protected function _buildMenuArray(Varien_Simplexml_Element $parent, $path = '', uasort($parentArr, [$this, '_sortMenu']); - foreach ($parentArr as $key => $value) { + foreach (array_keys($parentArr) as $key) { $last = $key; } if (isset($last)) { diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Grid.php index 180a228a288..efc441c2365 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Grid.php @@ -207,7 +207,7 @@ protected function _prepareCollection() */ protected function _setFilterValues($data) { - foreach ($data as $name => $value) { + foreach (array_keys($data) as $name) { $this->setFilter($name, $data[$name]); } return $this; diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Child/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Child/Grid.php index 1e8e12f3dd4..2a585eb5b7d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Child/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Child/Grid.php @@ -62,7 +62,7 @@ protected function _prepareColumns() { $result = parent::_prepareColumns(); - foreach ($this->_columns as $key => $value) { + foreach (array_keys($this->_columns) as $key) { if (in_array($key, $this->_columnsToRemove)) { unset($this->_columns[$key]); } else { diff --git a/app/code/core/Mage/Adminhtml/Block/Store/Switcher.php b/app/code/core/Mage/Adminhtml/Block/Store/Switcher.php index d0c60a17406..33442aa26b1 100644 --- a/app/code/core/Mage/Adminhtml/Block/Store/Switcher.php +++ b/app/code/core/Mage/Adminhtml/Block/Store/Switcher.php @@ -73,7 +73,7 @@ public function getWebsites() { $websites = Mage::app()->getWebsites(); if ($websiteIds = $this->getWebsiteIds()) { - foreach ($websites as $websiteId => $website) { + foreach (array_keys($websites) as $websiteId) { if (!in_array($websiteId, $websiteIds)) { unset($websites[$websiteId]); } @@ -140,7 +140,7 @@ public function getStores($group) } $stores = $group->getStores(); if ($storeIds = $this->getStoreIds()) { - foreach ($stores as $storeId => $store) { + foreach (array_keys($stores) as $storeId) { if (!in_array($storeId, $storeIds)) { unset($stores[$storeId]); } diff --git a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php index 9e369a45972..fc959e184ff 100644 --- a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php @@ -194,7 +194,7 @@ public function getButtonsHtml($area = null) { if ($this->_buttonsHtml === null) { $this->_buttonsHtml = parent::getButtonsHtml(); - foreach ($this->_children as $alias => $child) { + foreach (array_keys($this->_children) as $alias) { if (str_contains($alias, '_button')) { $this->unsetChild($alias); } diff --git a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php index a91f22b905a..955c2f871b0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php @@ -61,7 +61,7 @@ protected function _prepareForm() 'description' => $model->getDescription(), ]; if ($sessionData = Mage::getSingleton('adminhtml/session')->getData('urlrewrite_data', true)) { - foreach ($formValues as $key => $value) { + foreach (array_keys($formValues) as $key) { if (isset($sessionData[$key])) { $formValues[$key] = $sessionData[$key]; } diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php index af36a237924..5b701ae5133 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php @@ -481,7 +481,7 @@ public function getColumns() */ protected function _setFilterValues($data) { - foreach ($data as $columnId => $value) { + foreach (array_keys($data) as $columnId) { $column = $this->getColumn($columnId); if ($column instanceof Mage_Adminhtml_Block_Widget_Grid_Column && (!empty($data[$columnId]) || strlen($data[$columnId]) > 0) diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Action.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Action.php index 1fe5f9905b6..9bdad27dbbf 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Action.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Action.php @@ -109,7 +109,7 @@ protected function _toLinkHtml($action, Varien_Object $row) */ protected function _transformActionData(&$action, &$actionCaption, Varien_Object $row) { - foreach ($action as $attribute => $value) { + foreach (array_keys($action) as $attribute) { if (isset($action[$attribute]) && !is_array($action[$attribute])) { $this->getColumn()->setFormat($action[$attribute]); $action[$attribute] = parent::render($row); diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php index 94e9fae48a6..ca58c8f7fc6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php @@ -256,7 +256,7 @@ protected function _reorderTabs() asort($this->_tabPositions); $ordered = []; - foreach ($this->_tabPositions as $tabId => $position) { + foreach (array_keys($this->_tabPositions) as $tabId) { if (isset($this->_tabs[$tabId])) { $tab = $this->_tabs[$tabId]; $ordered[$tabId] = $tab; diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Admin/Page.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Admin/Page.php index e79b3daedc4..92bfd9d0639 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Admin/Page.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Admin/Page.php @@ -109,7 +109,7 @@ protected function _buildMenuArray(?Varien_Simplexml_Element $parent = null, $pa uasort($parentArr, [$this, '_sortMenu']); - foreach ($parentArr as $key => $value) { + foreach (array_keys($parentArr) as $key) { $last = $key; } if (isset($last)) { diff --git a/app/code/core/Mage/Api2/Model/Acl/Filter.php b/app/code/core/Mage/Api2/Model/Acl/Filter.php index 3494dfceb14..cefef4dd4f6 100644 --- a/app/code/core/Mage/Api2/Model/Acl/Filter.php +++ b/app/code/core/Mage/Api2/Model/Acl/Filter.php @@ -61,7 +61,7 @@ public function __construct(Mage_Api2_Model_Resource $resource) */ protected function _filter(array $allowedAttributes, array $data) { - foreach ($data as $attribute => $value) { + foreach (array_keys($data) as $attribute) { if (!in_array($attribute, $allowedAttributes)) { unset($data[$attribute]); } diff --git a/app/code/core/Mage/Api2/Model/Acl/Filter/Attribute/ResourcePermission.php b/app/code/core/Mage/Api2/Model/Acl/Filter/Attribute/ResourcePermission.php index 1016b87c227..f58a244ca00 100644 --- a/app/code/core/Mage/Api2/Model/Acl/Filter/Attribute/ResourcePermission.php +++ b/app/code/core/Mage/Api2/Model/Acl/Filter/Attribute/ResourcePermission.php @@ -103,7 +103,7 @@ public function getResourcesPermissions() $resourceModel->setResourceType($resource) ->setUserType($this->_userType); - foreach ($operations as $operation => $operationLabel) { + foreach (array_keys($operations) as $operation) { if (!$this->_hasEntityOnlyAttributes && $config->getResourceEntityOnlyAttributes($resource, $this->_userType, $operation) ) { diff --git a/app/code/core/Mage/Catalog/Model/Api2/Product.php b/app/code/core/Mage/Catalog/Model/Api2/Product.php index 586f1db4acd..f757413be4b 100644 --- a/app/code/core/Mage/Catalog/Model/Api2/Product.php +++ b/app/code/core/Mage/Catalog/Model/Api2/Product.php @@ -42,7 +42,7 @@ public function getAvailableAttributes($userType, $operation) } $excludedAttrs = $this->getExcludedAttributes($userType, $operation); $includedAttrs = $this->getIncludedAttributes($userType, $operation); - foreach ($attributes as $code => $label) { + foreach (array_keys($attributes) as $code) { if (in_array($code, $excludedAttrs) || ($includedAttrs && !in_array($code, $includedAttrs))) { unset($attributes[$code]); } diff --git a/app/code/core/Mage/Catalog/Model/Category.php b/app/code/core/Mage/Catalog/Model/Category.php index 58cd0b2c7c9..5ff10b609dc 100644 --- a/app/code/core/Mage/Catalog/Model/Category.php +++ b/app/code/core/Mage/Catalog/Model/Category.php @@ -346,7 +346,7 @@ public function getAttributes($noDesignAttributes = false) ->getSortedAttributes(); if ($noDesignAttributes) { - foreach ($result as $k => $a) { + foreach (array_keys($result) as $k) { if (in_array($k, $this->_designAttributes)) { unset($result[$k]); } diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Price.php b/app/code/core/Mage/Catalog/Model/Product/Type/Price.php index 62e6d7f86ae..df7d7f731c9 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Price.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Price.php @@ -300,7 +300,7 @@ public function getFormatedTierPrice($qty, $product) { $price = $product->getTierPrice($qty); if (is_array($price)) { - foreach ($price as $index => $value) { + foreach (array_keys($price) as $index) { $price[$index]['formated_price'] = Mage::app()->getStore()->convertPrice( $price[$index]['website_price'], true diff --git a/app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php b/app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php index 3a03e409ef5..7e962fb0b72 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php @@ -1152,7 +1152,7 @@ protected function _prepareDataForAllFields($category, $replaceFields = []) $table = $this->_getReadAdapter()->describeTable($table); $data = []; $idFieldName = Mage::getSingleton('catalog/category')->getIdFieldName(); - foreach ($table as $column => $columnData) { + foreach (array_keys($table) as $column) { if ($column != $idFieldName || $category->getData($column) !== null) { if (array_key_exists($column, $replaceFields)) { $value = $category->getData($replaceFields[$column]); diff --git a/app/code/core/Mage/Checkout/Model/Type/Onepage.php b/app/code/core/Mage/Checkout/Model/Type/Onepage.php index f1d8d4a5ced..2cdbe2eec65 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Onepage.php +++ b/app/code/core/Mage/Checkout/Model/Type/Onepage.php @@ -119,7 +119,7 @@ public function initCheckout() $checkout = $this->getCheckout(); $customerSession = $this->getCustomerSession(); if (is_array($checkout->getStepData())) { - foreach ($checkout->getStepData() as $step => $data) { + foreach (array_keys($checkout->getStepData()) as $step) { if (!($step === 'login' || $customerSession->isLoggedIn() && $step === 'billing')) { $checkout->setStepData($step, 'allow', false); } diff --git a/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php b/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php index db49ed16933..da23ea014ad 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php +++ b/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php @@ -136,7 +136,7 @@ public function attachProductChildrenAttributeMapping(array $parentProducts, $st } // end looping child products } // end looping attributes - foreach ($mapping as $key => $value) { + foreach (array_keys($mapping) as $key) { $mapping[$key]['product_ids'] = array_unique($mapping[$key]['product_ids']); } diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php index 73029d7952c..d3c9a73ac45 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -603,7 +603,7 @@ public function assocToXml(array $array, $rootName = '_') <$rootName> XML; $xml = new SimpleXMLElement($xmlstr); - foreach ($array as $key => $value) { + foreach (array_keys($array) as $key) { if (is_numeric($key)) { throw new Exception('Array root keys must not be numeric.'); } diff --git a/app/code/core/Mage/Core/Model/Cache.php b/app/code/core/Mage/Core/Model/Cache.php index fe97c2c491f..9965019bf1e 100644 --- a/app/code/core/Mage/Core/Model/Cache.php +++ b/app/code/core/Mage/Core/Model/Cache.php @@ -625,7 +625,7 @@ public function getInvalidatedTypes() $types = $this->_getInvalidatedTypes(); if ($types) { $allTypes = $this->getTypes(); - foreach ($types as $type => $flag) { + foreach (array_keys($types) as $type) { if (isset($allTypes[$type]) && $this->canUse($type)) { $invalidatedTypes[$type] = $allTypes[$type]; } diff --git a/app/code/core/Mage/Core/Model/Layout/Validator.php b/app/code/core/Mage/Core/Model/Layout/Validator.php index 9bedeaf8621..2d14731992b 100644 --- a/app/code/core/Mage/Core/Model/Layout/Validator.php +++ b/app/code/core/Mage/Core/Model/Layout/Validator.php @@ -108,7 +108,7 @@ public function getDisallowedBlocks() if (!count($this->_disallowedBlock)) { $disallowedBlockConfig = $this->_getDisallowedBlockConfigValue(); if (is_array($disallowedBlockConfig)) { - foreach ($disallowedBlockConfig as $blockName => $value) { + foreach (array_keys($disallowedBlockConfig) as $blockName) { $this->_disallowedBlock[] = $blockName; } } diff --git a/app/code/core/Mage/Core/Model/Locale.php b/app/code/core/Mage/Core/Model/Locale.php index d3b70a7c1cd..2a0c44563c3 100644 --- a/app/code/core/Mage/Core/Model/Locale.php +++ b/app/code/core/Mage/Core/Model/Locale.php @@ -247,7 +247,7 @@ protected function _getOptionLocales($translatedName = false) } } - foreach ($locales as $code => $active) { + foreach (array_keys($locales) as $code) { if (strstr($code, '_')) { if (!in_array($code, $allowed)) { continue; diff --git a/app/code/core/Mage/Core/Model/Log/Adapter.php b/app/code/core/Mage/Core/Model/Log/Adapter.php index 3bc190114c0..1a173c94d99 100644 --- a/app/code/core/Mage/Core/Model/Log/Adapter.php +++ b/app/code/core/Mage/Core/Model/Log/Adapter.php @@ -115,7 +115,7 @@ public function setFilterDataKeys($keys) protected function _filterDebugData($debugData) { if (is_array($debugData) && is_array($this->_debugReplacePrivateDataKeys)) { - foreach ($debugData as $key => $value) { + foreach (array_keys($debugData) as $key) { if (in_array($key, $this->_debugReplacePrivateDataKeys)) { $debugData[$key] = '****'; } else { diff --git a/app/code/core/Mage/Core/Model/Url/Rewrite.php b/app/code/core/Mage/Core/Model/Url/Rewrite.php index a9bae5f2912..929f39be12c 100644 --- a/app/code/core/Mage/Core/Model/Url/Rewrite.php +++ b/app/code/core/Mage/Core/Model/Url/Rewrite.php @@ -319,7 +319,7 @@ protected function _getQueryString() $queryParams = []; parse_str($_SERVER['QUERY_STRING'], $queryParams); $hasChanges = false; - foreach ($queryParams as $key => $value) { + foreach (array_keys($queryParams) as $key) { if (substr($key, 0, 3) === '___') { unset($queryParams[$key]); $hasChanges = true; diff --git a/app/code/core/Mage/Core/Model/Url/Rewrite/Request.php b/app/code/core/Mage/Core/Model/Url/Rewrite/Request.php index 80bf9ce24de..f6c14bf4b9a 100644 --- a/app/code/core/Mage/Core/Model/Url/Rewrite/Request.php +++ b/app/code/core/Mage/Core/Model/Url/Rewrite/Request.php @@ -306,7 +306,7 @@ protected function _getQueryString() $queryParams = []; parse_str($_SERVER['QUERY_STRING'], $queryParams); $hasChanges = false; - foreach ($queryParams as $key => $value) { + foreach (array_keys($queryParams) as $key) { if (substr($key, 0, 3) === '___') { unset($queryParams[$key]); $hasChanges = true; diff --git a/app/code/core/Mage/Customer/Model/Address/Api.php b/app/code/core/Mage/Customer/Model/Address/Api.php index 63120a58f38..9f779558882 100644 --- a/app/code/core/Mage/Customer/Model/Address/Api.php +++ b/app/code/core/Mage/Customer/Model/Address/Api.php @@ -55,7 +55,7 @@ public function items($customerId) $row[$attributeAlias] = $data[$attributeCode] ?? null; } - foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { + foreach (array_keys($this->getAllowedAttributes($address)) as $attributeCode) { if (isset($data[$attributeCode])) { $row[$attributeCode] = $data[$attributeCode]; } @@ -89,7 +89,7 @@ public function create($customerId, $addressData) $address = Mage::getModel('customer/address'); - foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { + foreach (array_keys($this->getAllowedAttributes($address)) as $attributeCode) { if (isset($addressData[$attributeCode])) { $address->setData($attributeCode, $addressData[$attributeCode]); } @@ -141,7 +141,7 @@ public function info($addressId) $result[$attributeAlias] = $address->getData($attributeCode); } - foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { + foreach (array_keys($this->getAllowedAttributes($address)) as $attributeCode) { $result[$attributeCode] = $address->getData($attributeCode); } @@ -169,7 +169,7 @@ public function update($addressId, $addressData) $this->_fault('not_exists'); } - foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { + foreach (array_keys($this->getAllowedAttributes($address)) as $attributeCode) { if (isset($addressData[$attributeCode])) { $address->setData($attributeCode, $addressData[$attributeCode]); } diff --git a/app/code/core/Mage/Customer/Model/Address/Api/V2.php b/app/code/core/Mage/Customer/Model/Address/Api/V2.php index 8616fec57a1..901b932eef7 100644 --- a/app/code/core/Mage/Customer/Model/Address/Api/V2.php +++ b/app/code/core/Mage/Customer/Model/Address/Api/V2.php @@ -40,7 +40,7 @@ public function create($customerId, $addressData) $address = Mage::getModel('customer/address'); - foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { + foreach (array_keys($this->getAllowedAttributes($address)) as $attributeCode) { if (isset($addressData->$attributeCode)) { $address->setData($attributeCode, $addressData->$attributeCode); } @@ -92,7 +92,7 @@ public function info($addressId) $result[$attributeAlias] = $address->getData($attributeCode); } - foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { + foreach (array_keys($this->getAllowedAttributes($address)) as $attributeCode) { $result[$attributeCode] = $address->getData($attributeCode); } @@ -120,7 +120,7 @@ public function update($addressId, $addressData) $this->_fault('not_exists'); } - foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { + foreach (array_keys($this->getAllowedAttributes($address)) as $attributeCode) { if (isset($addressData->$attributeCode)) { $address->setData($attributeCode, $addressData->$attributeCode); } diff --git a/app/code/core/Mage/Customer/Model/Customer/Api.php b/app/code/core/Mage/Customer/Model/Customer/Api.php index 16853c6c60e..f8daaa27a89 100644 --- a/app/code/core/Mage/Customer/Model/Customer/Api.php +++ b/app/code/core/Mage/Customer/Model/Customer/Api.php @@ -87,7 +87,7 @@ public function info($customerId, $attributes = null) $result[$attributeAlias] = $customer->getData($attributeCode); } - foreach ($this->getAllowedAttributes($customer, $attributes) as $attributeCode => $attribute) { + foreach (array_keys($this->getAllowedAttributes($customer, $attributes)) as $attributeCode) { $result[$attributeCode] = $customer->getData($attributeCode); } @@ -121,7 +121,7 @@ public function items($filters) foreach ($this->_mapAttributes as $attributeAlias => $attributeCode) { $row[$attributeAlias] = $data[$attributeCode] ?? null; } - foreach ($this->getAllowedAttributes($customer) as $attributeCode => $attribute) { + foreach (array_keys($this->getAllowedAttributes($customer)) as $attributeCode) { if (isset($data[$attributeCode])) { $row[$attributeCode] = $data[$attributeCode]; } @@ -149,7 +149,7 @@ public function update($customerId, $customerData) $this->_fault('not_exists'); } - foreach ($this->getAllowedAttributes($customer) as $attributeCode => $attribute) { + foreach (array_keys($this->getAllowedAttributes($customer)) as $attributeCode) { if (isset($customerData[$attributeCode])) { $customer->setData($attributeCode, $customerData[$attributeCode]); } diff --git a/app/code/core/Mage/Dataflow/Model/Batch.php b/app/code/core/Mage/Dataflow/Model/Batch.php index 1f727062e73..1235b8f468f 100644 --- a/app/code/core/Mage/Dataflow/Model/Batch.php +++ b/app/code/core/Mage/Dataflow/Model/Batch.php @@ -92,12 +92,12 @@ public function getFieldList() */ public function parseFieldList($row) { - foreach ($row as $fieldName => $value) { + foreach (array_keys($row) as $fieldName) { if (!in_array($fieldName, $this->_fieldList)) { $this->_fieldList[$fieldName] = $fieldName; } } - unset($fieldName, $value, $row); + unset($fieldName, $row); } /** diff --git a/app/code/core/Mage/Dataflow/Model/Session/Parser/Csv.php b/app/code/core/Mage/Dataflow/Model/Session/Parser/Csv.php index 1a15c400f15..fdf30b8c5f6 100644 --- a/app/code/core/Mage/Dataflow/Model/Session/Parser/Csv.php +++ b/app/code/core/Mage/Dataflow/Model/Session/Parser/Csv.php @@ -47,7 +47,7 @@ public function parse() $fields = $line; continue; } else { - foreach ($line as $j => $f) { + foreach (array_keys($line) as $j) { $fields[$j] = 'column' . ($j + 1); } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Abstract.php index 25c93a56c2e..01c39e4c918 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Abstract.php @@ -1594,7 +1594,7 @@ public function delete($object) ]; $this->_getWriteAdapter()->delete($this->getEntityTable(), $where); $this->loadAllAttributes($object); - foreach ($this->getAttributesByTable() as $table => $attributes) { + foreach (array_keys($this->getAttributesByTable()) as $table) { $this->_getWriteAdapter()->delete($table, $where); } } catch (Exception $e) { diff --git a/app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php b/app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php index 91b578e810a..1ecb2e87b92 100644 --- a/app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php +++ b/app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php @@ -790,7 +790,7 @@ protected function _prepareExport() '_custom_option_row_sku', '_custom_option_row_sort' ]; - foreach ($this->_storeIdToCode as $storeId => &$storeCode) { + foreach (array_keys($this->_storeIdToCode) as &$storeId) { $skip = false; $options = Mage::getResourceModel('catalog/product_option_collection') ->reset() @@ -961,7 +961,7 @@ protected function _prepareExport() $dataRow = array_merge($dataRow, array_shift($configurableData[$productId])); } if (!empty($rowMultiselects[$productId][$storeId])) { - foreach ($rowMultiselects[$productId][$storeId] as $attrKey => $attrVal) { + foreach (array_keys($rowMultiselects[$productId][$storeId]) as $attrKey) { if (isset($rowMultiselects[$productId][$storeId][$attrKey])) { $dataRow[$attrKey] = array_shift($rowMultiselects[$productId][$storeId][$attrKey]); } @@ -1039,7 +1039,7 @@ protected function _prepareExport() $dataRow = array_merge($dataRow, array_shift($configurableData[$productId])); } if (!empty($rowMultiselects[$productId][$storeId])) { - foreach ($rowMultiselects[$productId][$storeId] as $attrKey => $attrVal) { + foreach (array_keys($rowMultiselects[$productId][$storeId]) as $attrKey) { if (isset($rowMultiselects[$productId][$storeId][$attrKey])) { $dataRow[$attrKey] = array_shift($rowMultiselects[$productId][$storeId][$attrKey]); } diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php index 6c1771b734e..5fc9083546d 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php @@ -547,7 +547,7 @@ public function getEntityTypeCode() public function getRowScope(array $rowData) { $foundOptions = false; - foreach ($this->_multiSelectAttributes as $attrCode => $attribute) { + foreach (array_keys($this->_multiSelectAttributes) as $attrCode) { if ($rowData[$attrCode]) { $foundOptions = true; } diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php index 0a4cf80d21e..914c5be124f 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php @@ -1099,7 +1099,7 @@ protected function _saveCustomOptions() if ($productIds) { // update product entity table to show that product has options $customOptionsProducts = $customOptions['product_id']; - foreach ($customOptionsProducts as $key => $value) { + foreach (array_keys($customOptionsProducts) as $key) { if (!in_array($key, $productIds)) { unset($customOptionsProducts[$key]); } diff --git a/app/code/core/Mage/Index/Model/Event.php b/app/code/core/Mage/Index/Model/Event.php index 2035a5be359..d4dc4468a17 100644 --- a/app/code/core/Mage/Index/Model/Event.php +++ b/app/code/core/Mage/Index/Model/Event.php @@ -157,7 +157,7 @@ protected function _mergeNewDataRecursive($previous, $current) return $previous; } - foreach ($previous as $key => $value) { + foreach (array_keys($previous) as $key) { if (array_key_exists($key, $current) && !is_null($current[$key]) && is_array($previous[$key])) { if (!is_string($key) || is_array($current[$key])) { $current[$key] = $this->_mergeNewDataRecursive($previous[$key], $current[$key]); diff --git a/app/code/core/Mage/Install/Block/Db/Main.php b/app/code/core/Mage/Install/Block/Db/Main.php index 9f0789c1ea3..25791d2f5f8 100644 --- a/app/code/core/Mage/Install/Block/Db/Main.php +++ b/app/code/core/Mage/Install/Block/Db/Main.php @@ -77,7 +77,7 @@ public function getDatabaseBlock($type) public function getDatabaseBlocks() { $databases = []; - foreach ($this->_databases as $type => $blockData) { + foreach (array_keys($this->_databases) as $type) { $databases[] = $this->getDatabaseBlock($type); } return $databases; diff --git a/app/code/core/Mage/Install/Model/Installer/Console.php b/app/code/core/Mage/Install/Model/Installer/Console.php index 033d8db36a4..7c31a5007ab 100644 --- a/app/code/core/Mage/Install/Model/Installer/Console.php +++ b/app/code/core/Mage/Install/Model/Installer/Console.php @@ -155,7 +155,7 @@ public function setArgs($args = null) /** * Set args values */ - foreach ($this->_getOptions() as $name => $option) { + foreach (array_keys($this->_getOptions()) as $name) { $this->_args[$name] = $args[$name] ?? ''; } diff --git a/app/code/core/Mage/Install/Model/Installer/Db/Abstract.php b/app/code/core/Mage/Install/Model/Installer/Db/Abstract.php index 40155d07e4a..33b6de0c2ea 100644 --- a/app/code/core/Mage/Install/Model/Installer/Db/Abstract.php +++ b/app/code/core/Mage/Install/Model/Installer/Db/Abstract.php @@ -136,7 +136,7 @@ public function getRequiredExtensions() { $extensions = []; $configExt = (array)Mage::getConfig()->getNode(sprintf('install/databases/%s/extensions', $this->getModel())); - foreach ($configExt as $name => $value) { + foreach (array_keys($configExt) as $name) { $extensions[] = $name; } return $extensions; diff --git a/app/code/core/Mage/Page/Block/Template/Links.php b/app/code/core/Mage/Page/Block/Template/Links.php index b52e2f367eb..aacfd69b27e 100644 --- a/app/code/core/Mage/Page/Block/Template/Links.php +++ b/app/code/core/Mage/Page/Block/Template/Links.php @@ -242,7 +242,7 @@ protected function _getNewPosition($position = 0) } } else { $position = 0; - foreach ($this->_links as $k => $v) { + foreach (array_keys($this->_links) as $k) { $position = $k; } $position += 10; diff --git a/app/code/core/Mage/Paygate/Model/Authorizenet.php b/app/code/core/Mage/Paygate/Model/Authorizenet.php index 5659e2caac3..c32a8b69385 100644 --- a/app/code/core/Mage/Paygate/Model/Authorizenet.php +++ b/app/code/core/Mage/Paygate/Model/Authorizenet.php @@ -1475,7 +1475,7 @@ protected function _addTransaction( $payment->setTransactionAdditionalInfo($key, $value); } $transaction = $payment->addTransaction($transactionType, null, false, $message); - foreach ($transactionDetails as $key => $value) { + foreach (array_keys($transactionDetails) as $key) { $payment->unsetData($key); } $payment->unsLastTransId(); diff --git a/app/code/core/Mage/Payment/Block/Form/Cc.php b/app/code/core/Mage/Payment/Block/Form/Cc.php index 5435e7f4a75..08a12b4c037 100644 --- a/app/code/core/Mage/Payment/Block/Form/Cc.php +++ b/app/code/core/Mage/Payment/Block/Form/Cc.php @@ -47,7 +47,7 @@ public function getCcAvailableTypes() $availableTypes = $method->getConfigData('cctypes'); if ($availableTypes) { $availableTypes = explode(',', $availableTypes); - foreach ($types as $code => $name) { + foreach (array_keys($types) as $code) { if (!in_array($code, $availableTypes)) { unset($types[$code]); } diff --git a/app/code/core/Mage/Payment/Helper/Data.php b/app/code/core/Mage/Payment/Helper/Data.php index a7f9071c590..fed881ddeae 100644 --- a/app/code/core/Mage/Payment/Helper/Data.php +++ b/app/code/core/Mage/Payment/Helper/Data.php @@ -67,7 +67,7 @@ public function getMethodInstance($code) public function getStoreMethods($store = null, $quote = null) { $res = []; - foreach ($this->getPaymentMethods($store) as $code => $methodConfig) { + foreach (array_keys($this->getPaymentMethods($store)) as $code) { $prefix = self::XML_PATH_PAYMENT_METHODS . '/' . $code . '/'; if (!$model = Mage::getStoreConfig($prefix . 'model', $store)) { continue; @@ -166,7 +166,7 @@ public function getBillingAgreementMethods($store = null, $quote = null) public function getRecurringProfileMethods($store = null) { $result = []; - foreach ($this->getPaymentMethods($store) as $code => $data) { + foreach (array_keys($this->getPaymentMethods($store)) as $code) { $paymentMethodModelClassName = $this->getMethodModelClassName($code); if (!$paymentMethodModelClassName) { continue; @@ -244,7 +244,7 @@ public function getPaymentMethodList($sorted = true, $asLabelValue = false, $wit } if ($asLabelValue) { $labelValues = []; - foreach ($methods as $code => $title) { + foreach (array_keys($methods) as $code) { $labelValues[$code] = []; } foreach ($methods as $code => $title) { diff --git a/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement.php b/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement.php index ec75245e7e2..fca1a3d661e 100644 --- a/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement.php +++ b/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement.php @@ -58,7 +58,7 @@ protected function _afterSave(Mage_Core_Model_Abstract $object) /** @var Mage_Core_Model_Date $date */ $date = Mage::getSingleton('core/date'); - foreach ($rows as $key => $row) { + foreach (array_keys($rows) as $key) { /* * Converting dates */ diff --git a/app/code/core/Mage/Reports/Model/Totals.php b/app/code/core/Mage/Reports/Model/Totals.php index 33f899cc705..6b98422fdee 100644 --- a/app/code/core/Mage/Reports/Model/Totals.php +++ b/app/code/core/Mage/Reports/Model/Totals.php @@ -47,7 +47,7 @@ public function countTotals($grid, $from, $to) } $data = $item->getData(); - foreach ($columns as $field => $a) { + foreach (array_keys($columns) as $field) { if ($field !== '') { $columns[$field]['value'] += $data[$field] ?? 0; } diff --git a/app/code/core/Mage/Rule/Model/Action/Abstract.php b/app/code/core/Mage/Rule/Model/Action/Abstract.php index a810922d2f7..d8cb87fb7f4 100644 --- a/app/code/core/Mage/Rule/Model/Action/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Action/Abstract.php @@ -52,11 +52,11 @@ public function __construct() parent::__construct(); $this->loadAttributeOptions()->loadOperatorOptions()->loadValueOptions(); - foreach ($this->getAttributeOption() as $attr => $dummy) { + foreach (array_keys($this->getAttributeOption()) as $attr) { $this->setAttribute($attr); break; } - foreach ($this->getOperatorOption() as $operator => $dummy) { + foreach (array_keys($this->getOperatorOption()) as $operator) { $this->setOperator($operator); break; } diff --git a/app/code/core/Mage/Rule/Model/Condition/Abstract.php b/app/code/core/Mage/Rule/Model/Condition/Abstract.php index d2e67c86270..e31fbdda29c 100644 --- a/app/code/core/Mage/Rule/Model/Condition/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Condition/Abstract.php @@ -92,13 +92,13 @@ public function __construct() $this->loadAttributeOptions()->loadOperatorOptions()->loadValueOptions(); if ($options = $this->getAttributeOptions()) { - foreach ($options as $attr => $dummy) { + foreach (array_keys($options) as $attr) { $this->setAttribute($attr); break; } } if ($options = $this->getOperatorOptions()) { - foreach ($options as $operator => $dummy) { + foreach (array_keys($options) as $operator) { $this->setOperator($operator); break; } @@ -503,7 +503,7 @@ public function getTypeElementHtml() public function getAttributeElement() { if (is_null($this->getAttribute())) { - foreach ($this->getAttributeOption() as $k => $v) { + foreach (array_keys($this->getAttributeOption()) as $k) { $this->setAttribute($k); break; } diff --git a/app/code/core/Mage/Rule/Model/Condition/Combine.php b/app/code/core/Mage/Rule/Model/Condition/Combine.php index 79d4e693c38..1d9b0093d13 100644 --- a/app/code/core/Mage/Rule/Model/Condition/Combine.php +++ b/app/code/core/Mage/Rule/Model/Condition/Combine.php @@ -95,7 +95,7 @@ public function __construct() $this->loadAggregatorOptions(); if ($options = $this->getAggregatorOptions()) { - foreach ($options as $aggregator => $dummy) { + foreach (array_keys($options) as $aggregator) { $this->setAggregator($aggregator); break; } diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php b/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php index 52bf6a9b347..713bee21bab 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php @@ -125,7 +125,7 @@ protected function _prepareColumns() { $result = parent::_prepareColumns(); - foreach ($this->_columns as $key => $value) { + foreach (array_keys($this->_columns) as $key) { if (in_array($key, $this->_columnsToRemove)) { unset($this->_columns[$key]); } diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Order/Createdat.php b/app/code/core/Mage/Sales/Model/Resource/Report/Order/Createdat.php index 323ce47e00f..a9971351972 100644 --- a/app/code/core/Mage/Sales/Model/Resource/Report/Order/Createdat.php +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Order/Createdat.php @@ -230,7 +230,7 @@ protected function _aggregateByField($aggregationField, $from, $to) $adapter->query($select->insertFromSelect($this->getMainTable(), array_keys($columns))); // setup all columns to select SUM() except period, store_id and order_status - foreach ($columns as $k => $v) { + foreach (array_keys($columns) as $k) { $columns[$k] = new Zend_Db_Expr('SUM(' . $k . ')'); } $columns['period'] = 'period'; diff --git a/app/code/core/Mage/Sales/Model/Resource/Sale/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Sale/Collection.php index 1bf6ed99bf1..f2972e84cc9 100644 --- a/app/code/core/Mage/Sales/Model/Resource/Sale/Collection.php +++ b/app/code/core/Mage/Sales/Model/Resource/Sale/Collection.php @@ -182,7 +182,7 @@ public function load($printQuery = false, $logQuery = false) ->setWebsiteId(Mage::app()->getStore($storeId)->getWebsiteId()) ->setAvgNormalized($v['avgsale'] * $v['num_orders']); $this->_items[$storeId] = $storeObject; - foreach ($this->_totals as $key => $value) { + foreach (array_keys($this->_totals) as $key) { $this->_totals[$key] += $storeObject->getData($key); } } diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php index 43d089aa854..9525a968c57 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php @@ -183,7 +183,7 @@ $select->from(['e' => $this->getTable('sales_order_entity')]); $attributeIds = []; -foreach ($attributes as $code => $params) { +foreach (array_keys($attributes) as $code) { $attributes[$code] = $installer->getAttribute($orderEntityTypeId, $code); if ($attributes[$code]['backend_type'] != 'static') { $select->joinLeft( diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php index 3e9e34ea693..69722481f54 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php @@ -46,7 +46,7 @@ "); /* get order_payment attribute codes*/ -foreach ($attributesIds as $attributeCode => $attributeId) { +foreach (array_keys($attributesIds) as $attributeCode) { $attributesIds[$attributeCode] = $connection->fetchOne(" SELECT attribute_id FROM {$this->getTable('eav_attribute')} diff --git a/app/code/core/Mage/Shipping/Model/Rate/Result.php b/app/code/core/Mage/Shipping/Model/Rate/Result.php index fa06daacb29..bc7ad148a12 100644 --- a/app/code/core/Mage/Shipping/Model/Rate/Result.php +++ b/app/code/core/Mage/Shipping/Model/Rate/Result.php @@ -180,7 +180,7 @@ public function sortRatesByPrice() natsort($tmp); - foreach ($tmp as $i => $price) { + foreach (array_keys($tmp) as $i) { $result[] = $this->_rates[$i]; } diff --git a/app/code/core/Mage/Tag/Helper/Data.php b/app/code/core/Mage/Tag/Helper/Data.php index c86d4d5eee1..a2de68080cc 100644 --- a/app/code/core/Mage/Tag/Helper/Data.php +++ b/app/code/core/Mage/Tag/Helper/Data.php @@ -73,7 +73,7 @@ public function extractTags($tagNamesInString) */ public function cleanTags(array $tagNamesArr) { - foreach ($tagNamesArr as $key => $tagName) { + foreach (array_keys($tagNamesArr) as $key) { $tagNamesArr[$key] = trim($tagNamesArr[$key], '\''); $tagNamesArr[$key] = trim($tagNamesArr[$key]); if ($tagNamesArr[$key] == '') { diff --git a/app/code/core/Mage/Tag/controllers/IndexController.php b/app/code/core/Mage/Tag/controllers/IndexController.php index 54b26c441f7..833837c75b6 100644 --- a/app/code/core/Mage/Tag/controllers/IndexController.php +++ b/app/code/core/Mage/Tag/controllers/IndexController.php @@ -99,7 +99,7 @@ protected function _extractTags($tagNamesInString) */ protected function _cleanTags(array $tagNamesArr) { - foreach ($tagNamesArr as $key => $tagName) { + foreach (array_keys($tagNamesArr) as $key) { $tagNamesArr[$key] = trim($tagNamesArr[$key], '\''); $tagNamesArr[$key] = trim($tagNamesArr[$key]); if ($tagNamesArr[$key] == '') { diff --git a/app/code/core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php b/app/code/core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php index ed49099010c..f6ed065e028 100644 --- a/app/code/core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php +++ b/app/code/core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php @@ -74,7 +74,7 @@ public function afterLoad($object) { $data = $this->_getResource()->loadProductData($object, $this->getAttribute()); - foreach ($data as $i => $row) { + foreach (array_keys($data) as $i) { if ($data[$i]['website_id'] == 0) { $rate = Mage::app()->getStore()->getBaseCurrency()->getRate(Mage::app()->getBaseCurrencyCode()); if ($rate) { diff --git a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Attribute/Edit/AttributeForm.php b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Attribute/Edit/AttributeForm.php index 9683e4322cd..1344cfc1a92 100644 --- a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Attribute/Edit/AttributeForm.php +++ b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Attribute/Edit/AttributeForm.php @@ -45,7 +45,7 @@ public function getData(FixtureInterface $fixture = null, Element $element = nul { $data = []; if ($fixture === null) { - foreach ($this->tabs as $tabName => $tab) { + foreach (array_keys($this->tabs) as $tabName) { $this->openTab($tabName); $tabData = $this->getTabElement($tabName)->getDataFormTab(); $data = array_merge($data, $tabData); diff --git a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Edit/Tab/Prices.php b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Edit/Tab/Prices.php index 3346dcc17a8..657f84a8239 100644 --- a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Edit/Tab/Prices.php +++ b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Edit/Tab/Prices.php @@ -54,7 +54,7 @@ class Prices extends Tab public function fillFormTab(array $fields, Element $element = null) { $context = $element ? $element : $this->_rootElement; - foreach ($this->childrenForm as $key => $value) { + foreach (array_keys($this->childrenForm) as $key) { if (isset($fields[$key])) { $this->fillOptionsPrices([$key => $fields[$key]], $context); unset($fields[$key]); @@ -91,7 +91,7 @@ public function getDataFormTab($fields = null, Element $element = null) { $result = []; $context = $element ? $element : $this->_rootElement; - foreach ($this->childrenForm as $key => $value) { + foreach (array_keys($this->childrenForm) as $key) { if (isset($fields[$key])) { $result[$key] = $this->getOptionsPrices([$key => $fields[$key]], $context); unset($fields[$key]); diff --git a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/ProductForm.php b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/ProductForm.php index 584a8f25fbc..565b823b7c5 100644 --- a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/ProductForm.php +++ b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/ProductForm.php @@ -341,7 +341,7 @@ public function getRequireNoticeAttributes(FixtureInterface $product) { $data = []; $tabs = $this->getFieldsByTabs($product); - foreach ($tabs as $tabName => $fields) { + foreach (array_keys($tabs) as $tabName) { $tab = $this->getTabElement($tabName); $this->openTab($tabName); $errors = $tab->getRequireNoticeMessages(); diff --git a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Widget/FormTabs.php b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Widget/FormTabs.php index 8d9596cda76..a0c24f0c42d 100644 --- a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Widget/FormTabs.php +++ b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Widget/FormTabs.php @@ -135,7 +135,7 @@ protected function fillTabs(array $tabs, Element $element = null) */ protected function fillMissedFields() { - foreach ($this->tabs as $tabName => $tabData) { + foreach (array_keys($this->tabs) as $tabName) { $tabElement = $this->getTabElement($tabName); if ($this->openTab($tabName)) { $mapping = $tabElement->dataMapping($this->unassignedFields); @@ -174,7 +174,7 @@ public function getData(FixtureInterface $fixture = null, Element $element = nul $data = []; if (null === $fixture) { - foreach ($this->tabs as $tabName => $tab) { + foreach (array_keys($this->tabs) as $tabName) { $this->openTab($tabName); $tabData = $this->getTabElement($tabName)->getDataFormTab(); $data = array_merge($data, $tabData); diff --git a/dev/tests/functional/tests/app/Mage/Bundle/Test/Handler/Curl.php b/dev/tests/functional/tests/app/Mage/Bundle/Test/Handler/Curl.php index e4777d9f973..eb79bfc90ef 100644 --- a/dev/tests/functional/tests/app/Mage/Bundle/Test/Handler/Curl.php +++ b/dev/tests/functional/tests/app/Mage/Bundle/Test/Handler/Curl.php @@ -146,7 +146,7 @@ protected function prepareBundleSelections(array $bundleData) */ protected function prepareItemSelectionData(array $selections, array $products) { - foreach ($selections as $key => $selection) { + foreach (array_keys($selections) as $key) { $selections[$key]['product_id'] = $products[$key]->getId(); unset($selections[$key]['sku']); $selections[$key]['delete'] = ''; @@ -163,7 +163,7 @@ protected function prepareItemSelectionData(array $selections, array $products) */ protected function prepareBundleOptions(array $bundleData) { - foreach ($bundleData as $key => $option) { + foreach (array_keys($bundleData) as $key) { $bundleData[$key] = array_intersect_key($bundleData[$key], array_flip($this->optionsFields)); $bundleData[$key]['delete'] = ''; } diff --git a/dev/tests/functional/tests/app/Mage/Catalog/Test/TestStep/UpdateConfigurableProductStep/DeleteOptionsSubStep.php b/dev/tests/functional/tests/app/Mage/Catalog/Test/TestStep/UpdateConfigurableProductStep/DeleteOptionsSubStep.php index 6b18d2b8ea3..16d05ab359c 100644 --- a/dev/tests/functional/tests/app/Mage/Catalog/Test/TestStep/UpdateConfigurableProductStep/DeleteOptionsSubStep.php +++ b/dev/tests/functional/tests/app/Mage/Catalog/Test/TestStep/UpdateConfigurableProductStep/DeleteOptionsSubStep.php @@ -86,7 +86,7 @@ protected function searchKeysForOption($optionIndex) { $keys = []; $originalProductAssignedProducts = $this->getOriginalProductAssignedProducts(); - foreach ($originalProductAssignedProducts as $key => $product) { + foreach (array_keys($originalProductAssignedProducts) as $key) { if (strpos($key, 'option_key_' . $optionIndex) !== false) { $keys[] = $key; } diff --git a/dev/tests/functional/tests/app/Mage/Customer/Test/Handler/Customer/Curl.php b/dev/tests/functional/tests/app/Mage/Customer/Test/Handler/Customer/Curl.php index 68f2f85b69a..23d27ff801b 100644 --- a/dev/tests/functional/tests/app/Mage/Customer/Test/Handler/Customer/Curl.php +++ b/dev/tests/functional/tests/app/Mage/Customer/Test/Handler/Customer/Curl.php @@ -131,7 +131,7 @@ public function persist(FixtureInterface $customer = null) */ protected function checkForUpdateData(array $data) { - foreach ($data as $key => $field) { + foreach (array_keys($data) as $key) { if (in_array($key, $this->updatingFields)) { return true; } diff --git a/dev/tests/functional/tests/app/Mage/Weee/Test/Constraint/AssertFptApplied.php b/dev/tests/functional/tests/app/Mage/Weee/Test/Constraint/AssertFptApplied.php index c1b61df6d23..baf99e0e016 100644 --- a/dev/tests/functional/tests/app/Mage/Weee/Test/Constraint/AssertFptApplied.php +++ b/dev/tests/functional/tests/app/Mage/Weee/Test/Constraint/AssertFptApplied.php @@ -145,7 +145,7 @@ protected function clearShoppingCart() protected function getPrices() { $actualPrices = []; - foreach ($this->expectedPrices as $priceType => $prices) { + foreach (array_keys($this->expectedPrices) as $priceType) { $actualPrices[$priceType] = $this->{'get' . ucfirst($priceType) . 'Price'}(); } diff --git a/lib/Varien/Convert/Parser/Csv.php b/lib/Varien/Convert/Parser/Csv.php index f857c3b85a8..4550d155691 100644 --- a/lib/Varien/Convert/Parser/Csv.php +++ b/lib/Varien/Convert/Parser/Csv.php @@ -44,7 +44,7 @@ public function parse() $fields = $line; continue; } else { - foreach ($line as $j => $f) { + foreach (array_keys($line) as $j) { $fields[$j] = 'column' . ($j + 1); } } @@ -87,7 +87,7 @@ public function parseTest() $fields = $line; continue; } else { - foreach ($line as $j => $f) { + foreach (array_keys($line) as $j) { $fields[$j] = 'column' . ($j + 1); } } diff --git a/lib/Varien/Db/Statement/Pdo/Mysql.php b/lib/Varien/Db/Statement/Pdo/Mysql.php index b23cb8435fa..d5f83882237 100644 --- a/lib/Varien/Db/Statement/Pdo/Mysql.php +++ b/lib/Varien/Db/Statement/Pdo/Mysql.php @@ -33,7 +33,7 @@ public function _executeWithBinding(array $params) { // Check whether we deal with named bind $isPositionalBind = true; - foreach ($params as $k => $v) { + foreach (array_keys($params) as $k) { if (!is_int($k)) { $isPositionalBind = false; break; diff --git a/lib/Varien/Http/Adapter/Curl.php b/lib/Varien/Http/Adapter/Curl.php index 56e9359a23f..1e9fd81f16b 100644 --- a/lib/Varien/Http/Adapter/Curl.php +++ b/lib/Varien/Http/Adapter/Curl.php @@ -75,7 +75,7 @@ protected function _applyConfig() $verifyHost = isset($this->_config['verifyhost']) ? $this->_config['verifyhost'] : 0; curl_setopt($this->_getResource(), CURLOPT_SSL_VERIFYHOST, $verifyHost); - foreach ($this->_config as $param => $curlOption) { + foreach (array_keys($this->_config) as $param) { if (array_key_exists($param, $this->_allowedParams)) { curl_setopt($this->_getResource(), $this->_allowedParams[$param], $this->_config[$param]); } diff --git a/lib/Varien/Object.php b/lib/Varien/Object.php index bfd0f11bcff..968d5b0fc02 100644 --- a/lib/Varien/Object.php +++ b/lib/Varien/Object.php @@ -292,7 +292,7 @@ public function unsetData($key = null) public function unsetOldData($key = null) { if (is_null($key)) { - foreach ($this->_oldFieldsMap as $key => $newFieldName) { + foreach (array_keys($this->_oldFieldsMap) as $key) { unset($this->_data[$key]); } } else { diff --git a/lib/Varien/Object/Cache.php b/lib/Varien/Object/Cache.php index 11b6cc23775..24047b87356 100644 --- a/lib/Varien/Object/Cache.php +++ b/lib/Varien/Object/Cache.php @@ -241,7 +241,7 @@ public function delete($idx) } if (isset($this->_objectReferences[$idx])) { - foreach ($this->_references as $r => $dummy) { + foreach (array_keys($this->_references) as $r) { unset($this->_references[$r]); } unset($this->_objectReferences[$idx]); diff --git a/phpstan.dist.baseline.neon b/phpstan.dist.baseline.neon index 8fd0d3944fa..21489364a42 100644 --- a/phpstan.dist.baseline.neon +++ b/phpstan.dist.baseline.neon @@ -3400,11 +3400,6 @@ parameters: count: 1 path: app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php - - - message: "#^Offset int\\|string on non\\-empty\\-array\\ in isset\\(\\) always exists and is not nullable\\.$#" - count: 2 - path: app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php - - message: "#^Variable \\$collection might not be defined\\.$#" count: 1 From 370db1d5a9ccec9ef7723d7433e267e396628234 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Sat, 27 Jul 2024 19:16:39 +0200 Subject: [PATCH 02/13] Revert "Rector: CQ - UnusedForeachValueToArrayKeysRector (#1)" This reverts commit 3d7eaf63f2211a9e1a8defe8c29e8f6da889ab2e. --- app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php | 4 ++-- app/code/core/Mage/Adminhtml/Block/Page/Menu.php | 2 +- app/code/core/Mage/Adminhtml/Block/Report/Grid.php | 2 +- .../Adminhtml/Block/Sales/Transactions/Child/Grid.php | 2 +- app/code/core/Mage/Adminhtml/Block/Store/Switcher.php | 4 ++-- app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php | 2 +- .../core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php | 2 +- app/code/core/Mage/Adminhtml/Block/Widget/Grid.php | 2 +- .../Block/Widget/Grid/Column/Renderer/Action.php | 2 +- app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php | 2 +- .../Adminhtml/Model/System/Config/Source/Admin/Page.php | 2 +- app/code/core/Mage/Api2/Model/Acl/Filter.php | 2 +- .../Model/Acl/Filter/Attribute/ResourcePermission.php | 2 +- app/code/core/Mage/Catalog/Model/Api2/Product.php | 2 +- app/code/core/Mage/Catalog/Model/Category.php | 2 +- app/code/core/Mage/Catalog/Model/Product/Type/Price.php | 2 +- .../core/Mage/Catalog/Model/Resource/Category/Flat.php | 2 +- app/code/core/Mage/Checkout/Model/Type/Onepage.php | 2 +- .../Mage/ConfigurableSwatches/Helper/Mediafallback.php | 2 +- app/code/core/Mage/Core/Helper/Data.php | 2 +- app/code/core/Mage/Core/Model/Cache.php | 2 +- app/code/core/Mage/Core/Model/Layout/Validator.php | 2 +- app/code/core/Mage/Core/Model/Locale.php | 2 +- app/code/core/Mage/Core/Model/Log/Adapter.php | 2 +- app/code/core/Mage/Core/Model/Url/Rewrite.php | 2 +- app/code/core/Mage/Core/Model/Url/Rewrite/Request.php | 2 +- app/code/core/Mage/Customer/Model/Address/Api.php | 8 ++++---- app/code/core/Mage/Customer/Model/Address/Api/V2.php | 6 +++--- app/code/core/Mage/Customer/Model/Customer/Api.php | 6 +++--- app/code/core/Mage/Dataflow/Model/Batch.php | 4 ++-- app/code/core/Mage/Dataflow/Model/Session/Parser/Csv.php | 2 +- app/code/core/Mage/Eav/Model/Entity/Abstract.php | 2 +- .../Mage/ImportExport/Model/Export/Entity/Product.php | 6 +++--- .../Mage/ImportExport/Model/Import/Entity/Customer.php | 2 +- .../Mage/ImportExport/Model/Import/Entity/Product.php | 2 +- app/code/core/Mage/Index/Model/Event.php | 2 +- app/code/core/Mage/Install/Block/Db/Main.php | 2 +- app/code/core/Mage/Install/Model/Installer/Console.php | 2 +- .../core/Mage/Install/Model/Installer/Db/Abstract.php | 2 +- app/code/core/Mage/Page/Block/Template/Links.php | 2 +- app/code/core/Mage/Paygate/Model/Authorizenet.php | 2 +- app/code/core/Mage/Payment/Block/Form/Cc.php | 2 +- app/code/core/Mage/Payment/Helper/Data.php | 6 +++--- .../core/Mage/Paypal/Model/Resource/Report/Settlement.php | 2 +- app/code/core/Mage/Reports/Model/Totals.php | 2 +- app/code/core/Mage/Rule/Model/Action/Abstract.php | 4 ++-- app/code/core/Mage/Rule/Model/Condition/Abstract.php | 6 +++--- app/code/core/Mage/Rule/Model/Condition/Combine.php | 2 +- .../Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php | 2 +- .../Mage/Sales/Model/Resource/Report/Order/Createdat.php | 2 +- .../core/Mage/Sales/Model/Resource/Sale/Collection.php | 2 +- .../sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php | 2 +- .../sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php | 2 +- app/code/core/Mage/Shipping/Model/Rate/Result.php | 2 +- app/code/core/Mage/Tag/Helper/Data.php | 2 +- app/code/core/Mage/Tag/controllers/IndexController.php | 2 +- .../core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php | 2 +- .../Catalog/Product/Attribute/Edit/AttributeForm.php | 2 +- .../Test/Block/Catalog/Product/Edit/Tab/Prices.php | 4 ++-- .../Adminhtml/Test/Block/Catalog/Product/ProductForm.php | 2 +- .../app/Mage/Adminhtml/Test/Block/Widget/FormTabs.php | 4 ++-- .../tests/app/Mage/Bundle/Test/Handler/Curl.php | 4 ++-- .../DeleteOptionsSubStep.php | 2 +- .../app/Mage/Customer/Test/Handler/Customer/Curl.php | 2 +- .../app/Mage/Weee/Test/Constraint/AssertFptApplied.php | 2 +- lib/Varien/Convert/Parser/Csv.php | 4 ++-- lib/Varien/Db/Statement/Pdo/Mysql.php | 2 +- lib/Varien/Http/Adapter/Curl.php | 2 +- lib/Varien/Object.php | 2 +- lib/Varien/Object/Cache.php | 2 +- phpstan.dist.baseline.neon | 5 +++++ 71 files changed, 96 insertions(+), 91 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php index afc5f13938c..700d3b3b17d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php @@ -215,7 +215,7 @@ public function getChartUrl($directUrl = true) $dateStart->addMonth(1); break; } - foreach (array_keys($this->getAllSeries()) as $index) { + foreach ($this->getAllSeries() as $index => $serie) { if (in_array($d, $this->_axisLabels['x'])) { $datas[$index][] = (float)array_shift($this->_allSeries[$index]); } else { @@ -328,7 +328,7 @@ public function getChartUrl($directUrl = true) if (count($this->_axisLabels)) { $params['chxt'] = implode(',', array_keys($this->_axisLabels)); $indexid = 0; - foreach (array_keys($this->_axisLabels) as $idx) { + foreach ($this->_axisLabels as $idx => $labels) { if ($idx === 'x') { /** * Format date diff --git a/app/code/core/Mage/Adminhtml/Block/Page/Menu.php b/app/code/core/Mage/Adminhtml/Block/Page/Menu.php index 20bb44f96f4..d4872f9158d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Page/Menu.php +++ b/app/code/core/Mage/Adminhtml/Block/Page/Menu.php @@ -164,7 +164,7 @@ protected function _buildMenuArray(Varien_Simplexml_Element $parent, $path = '', uasort($parentArr, [$this, '_sortMenu']); - foreach (array_keys($parentArr) as $key) { + foreach ($parentArr as $key => $value) { $last = $key; } if (isset($last)) { diff --git a/app/code/core/Mage/Adminhtml/Block/Report/Grid.php b/app/code/core/Mage/Adminhtml/Block/Report/Grid.php index efc441c2365..180a228a288 100644 --- a/app/code/core/Mage/Adminhtml/Block/Report/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Report/Grid.php @@ -207,7 +207,7 @@ protected function _prepareCollection() */ protected function _setFilterValues($data) { - foreach (array_keys($data) as $name) { + foreach ($data as $name => $value) { $this->setFilter($name, $data[$name]); } return $this; diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Child/Grid.php b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Child/Grid.php index 2a585eb5b7d..1e8e12f3dd4 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Child/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Transactions/Child/Grid.php @@ -62,7 +62,7 @@ protected function _prepareColumns() { $result = parent::_prepareColumns(); - foreach (array_keys($this->_columns) as $key) { + foreach ($this->_columns as $key => $value) { if (in_array($key, $this->_columnsToRemove)) { unset($this->_columns[$key]); } else { diff --git a/app/code/core/Mage/Adminhtml/Block/Store/Switcher.php b/app/code/core/Mage/Adminhtml/Block/Store/Switcher.php index 33442aa26b1..d0c60a17406 100644 --- a/app/code/core/Mage/Adminhtml/Block/Store/Switcher.php +++ b/app/code/core/Mage/Adminhtml/Block/Store/Switcher.php @@ -73,7 +73,7 @@ public function getWebsites() { $websites = Mage::app()->getWebsites(); if ($websiteIds = $this->getWebsiteIds()) { - foreach (array_keys($websites) as $websiteId) { + foreach ($websites as $websiteId => $website) { if (!in_array($websiteId, $websiteIds)) { unset($websites[$websiteId]); } @@ -140,7 +140,7 @@ public function getStores($group) } $stores = $group->getStores(); if ($storeIds = $this->getStoreIds()) { - foreach (array_keys($stores) as $storeId) { + foreach ($stores as $storeId => $store) { if (!in_array($storeId, $storeIds)) { unset($stores[$storeId]); } diff --git a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php index fc959e184ff..9e369a45972 100644 --- a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php +++ b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php @@ -194,7 +194,7 @@ public function getButtonsHtml($area = null) { if ($this->_buttonsHtml === null) { $this->_buttonsHtml = parent::getButtonsHtml(); - foreach (array_keys($this->_children) as $alias) { + foreach ($this->_children as $alias => $child) { if (str_contains($alias, '_button')) { $this->unsetChild($alias); } diff --git a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php index 955c2f871b0..a91f22b905a 100644 --- a/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit/Form.php @@ -61,7 +61,7 @@ protected function _prepareForm() 'description' => $model->getDescription(), ]; if ($sessionData = Mage::getSingleton('adminhtml/session')->getData('urlrewrite_data', true)) { - foreach (array_keys($formValues) as $key) { + foreach ($formValues as $key => $value) { if (isset($sessionData[$key])) { $formValues[$key] = $sessionData[$key]; } diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php index 5b701ae5133..af36a237924 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php @@ -481,7 +481,7 @@ public function getColumns() */ protected function _setFilterValues($data) { - foreach (array_keys($data) as $columnId) { + foreach ($data as $columnId => $value) { $column = $this->getColumn($columnId); if ($column instanceof Mage_Adminhtml_Block_Widget_Grid_Column && (!empty($data[$columnId]) || strlen($data[$columnId]) > 0) diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Action.php b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Action.php index 9bdad27dbbf..1fe5f9905b6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Action.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Action.php @@ -109,7 +109,7 @@ protected function _toLinkHtml($action, Varien_Object $row) */ protected function _transformActionData(&$action, &$actionCaption, Varien_Object $row) { - foreach (array_keys($action) as $attribute) { + foreach ($action as $attribute => $value) { if (isset($action[$attribute]) && !is_array($action[$attribute])) { $this->getColumn()->setFormat($action[$attribute]); $action[$attribute] = parent::render($row); diff --git a/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php b/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php index ca58c8f7fc6..94e9fae48a6 100644 --- a/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php +++ b/app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php @@ -256,7 +256,7 @@ protected function _reorderTabs() asort($this->_tabPositions); $ordered = []; - foreach (array_keys($this->_tabPositions) as $tabId) { + foreach ($this->_tabPositions as $tabId => $position) { if (isset($this->_tabs[$tabId])) { $tab = $this->_tabs[$tabId]; $ordered[$tabId] = $tab; diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Admin/Page.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Admin/Page.php index 92bfd9d0639..e79b3daedc4 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Admin/Page.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Admin/Page.php @@ -109,7 +109,7 @@ protected function _buildMenuArray(?Varien_Simplexml_Element $parent = null, $pa uasort($parentArr, [$this, '_sortMenu']); - foreach (array_keys($parentArr) as $key) { + foreach ($parentArr as $key => $value) { $last = $key; } if (isset($last)) { diff --git a/app/code/core/Mage/Api2/Model/Acl/Filter.php b/app/code/core/Mage/Api2/Model/Acl/Filter.php index cefef4dd4f6..3494dfceb14 100644 --- a/app/code/core/Mage/Api2/Model/Acl/Filter.php +++ b/app/code/core/Mage/Api2/Model/Acl/Filter.php @@ -61,7 +61,7 @@ public function __construct(Mage_Api2_Model_Resource $resource) */ protected function _filter(array $allowedAttributes, array $data) { - foreach (array_keys($data) as $attribute) { + foreach ($data as $attribute => $value) { if (!in_array($attribute, $allowedAttributes)) { unset($data[$attribute]); } diff --git a/app/code/core/Mage/Api2/Model/Acl/Filter/Attribute/ResourcePermission.php b/app/code/core/Mage/Api2/Model/Acl/Filter/Attribute/ResourcePermission.php index f58a244ca00..1016b87c227 100644 --- a/app/code/core/Mage/Api2/Model/Acl/Filter/Attribute/ResourcePermission.php +++ b/app/code/core/Mage/Api2/Model/Acl/Filter/Attribute/ResourcePermission.php @@ -103,7 +103,7 @@ public function getResourcesPermissions() $resourceModel->setResourceType($resource) ->setUserType($this->_userType); - foreach (array_keys($operations) as $operation) { + foreach ($operations as $operation => $operationLabel) { if (!$this->_hasEntityOnlyAttributes && $config->getResourceEntityOnlyAttributes($resource, $this->_userType, $operation) ) { diff --git a/app/code/core/Mage/Catalog/Model/Api2/Product.php b/app/code/core/Mage/Catalog/Model/Api2/Product.php index f757413be4b..586f1db4acd 100644 --- a/app/code/core/Mage/Catalog/Model/Api2/Product.php +++ b/app/code/core/Mage/Catalog/Model/Api2/Product.php @@ -42,7 +42,7 @@ public function getAvailableAttributes($userType, $operation) } $excludedAttrs = $this->getExcludedAttributes($userType, $operation); $includedAttrs = $this->getIncludedAttributes($userType, $operation); - foreach (array_keys($attributes) as $code) { + foreach ($attributes as $code => $label) { if (in_array($code, $excludedAttrs) || ($includedAttrs && !in_array($code, $includedAttrs))) { unset($attributes[$code]); } diff --git a/app/code/core/Mage/Catalog/Model/Category.php b/app/code/core/Mage/Catalog/Model/Category.php index 5ff10b609dc..58cd0b2c7c9 100644 --- a/app/code/core/Mage/Catalog/Model/Category.php +++ b/app/code/core/Mage/Catalog/Model/Category.php @@ -346,7 +346,7 @@ public function getAttributes($noDesignAttributes = false) ->getSortedAttributes(); if ($noDesignAttributes) { - foreach (array_keys($result) as $k) { + foreach ($result as $k => $a) { if (in_array($k, $this->_designAttributes)) { unset($result[$k]); } diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Price.php b/app/code/core/Mage/Catalog/Model/Product/Type/Price.php index df7d7f731c9..62e6d7f86ae 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Price.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Price.php @@ -300,7 +300,7 @@ public function getFormatedTierPrice($qty, $product) { $price = $product->getTierPrice($qty); if (is_array($price)) { - foreach (array_keys($price) as $index) { + foreach ($price as $index => $value) { $price[$index]['formated_price'] = Mage::app()->getStore()->convertPrice( $price[$index]['website_price'], true diff --git a/app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php b/app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php index 7e962fb0b72..3a03e409ef5 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php @@ -1152,7 +1152,7 @@ protected function _prepareDataForAllFields($category, $replaceFields = []) $table = $this->_getReadAdapter()->describeTable($table); $data = []; $idFieldName = Mage::getSingleton('catalog/category')->getIdFieldName(); - foreach (array_keys($table) as $column) { + foreach ($table as $column => $columnData) { if ($column != $idFieldName || $category->getData($column) !== null) { if (array_key_exists($column, $replaceFields)) { $value = $category->getData($replaceFields[$column]); diff --git a/app/code/core/Mage/Checkout/Model/Type/Onepage.php b/app/code/core/Mage/Checkout/Model/Type/Onepage.php index 2cdbe2eec65..f1d8d4a5ced 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Onepage.php +++ b/app/code/core/Mage/Checkout/Model/Type/Onepage.php @@ -119,7 +119,7 @@ public function initCheckout() $checkout = $this->getCheckout(); $customerSession = $this->getCustomerSession(); if (is_array($checkout->getStepData())) { - foreach (array_keys($checkout->getStepData()) as $step) { + foreach ($checkout->getStepData() as $step => $data) { if (!($step === 'login' || $customerSession->isLoggedIn() && $step === 'billing')) { $checkout->setStepData($step, 'allow', false); } diff --git a/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php b/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php index da23ea014ad..db49ed16933 100644 --- a/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php +++ b/app/code/core/Mage/ConfigurableSwatches/Helper/Mediafallback.php @@ -136,7 +136,7 @@ public function attachProductChildrenAttributeMapping(array $parentProducts, $st } // end looping child products } // end looping attributes - foreach (array_keys($mapping) as $key) { + foreach ($mapping as $key => $value) { $mapping[$key]['product_ids'] = array_unique($mapping[$key]['product_ids']); } diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php index d3c9a73ac45..73029d7952c 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -603,7 +603,7 @@ public function assocToXml(array $array, $rootName = '_') <$rootName> XML; $xml = new SimpleXMLElement($xmlstr); - foreach (array_keys($array) as $key) { + foreach ($array as $key => $value) { if (is_numeric($key)) { throw new Exception('Array root keys must not be numeric.'); } diff --git a/app/code/core/Mage/Core/Model/Cache.php b/app/code/core/Mage/Core/Model/Cache.php index 9965019bf1e..fe97c2c491f 100644 --- a/app/code/core/Mage/Core/Model/Cache.php +++ b/app/code/core/Mage/Core/Model/Cache.php @@ -625,7 +625,7 @@ public function getInvalidatedTypes() $types = $this->_getInvalidatedTypes(); if ($types) { $allTypes = $this->getTypes(); - foreach (array_keys($types) as $type) { + foreach ($types as $type => $flag) { if (isset($allTypes[$type]) && $this->canUse($type)) { $invalidatedTypes[$type] = $allTypes[$type]; } diff --git a/app/code/core/Mage/Core/Model/Layout/Validator.php b/app/code/core/Mage/Core/Model/Layout/Validator.php index 2d14731992b..9bedeaf8621 100644 --- a/app/code/core/Mage/Core/Model/Layout/Validator.php +++ b/app/code/core/Mage/Core/Model/Layout/Validator.php @@ -108,7 +108,7 @@ public function getDisallowedBlocks() if (!count($this->_disallowedBlock)) { $disallowedBlockConfig = $this->_getDisallowedBlockConfigValue(); if (is_array($disallowedBlockConfig)) { - foreach (array_keys($disallowedBlockConfig) as $blockName) { + foreach ($disallowedBlockConfig as $blockName => $value) { $this->_disallowedBlock[] = $blockName; } } diff --git a/app/code/core/Mage/Core/Model/Locale.php b/app/code/core/Mage/Core/Model/Locale.php index 2a0c44563c3..d3b70a7c1cd 100644 --- a/app/code/core/Mage/Core/Model/Locale.php +++ b/app/code/core/Mage/Core/Model/Locale.php @@ -247,7 +247,7 @@ protected function _getOptionLocales($translatedName = false) } } - foreach (array_keys($locales) as $code) { + foreach ($locales as $code => $active) { if (strstr($code, '_')) { if (!in_array($code, $allowed)) { continue; diff --git a/app/code/core/Mage/Core/Model/Log/Adapter.php b/app/code/core/Mage/Core/Model/Log/Adapter.php index 1a173c94d99..3bc190114c0 100644 --- a/app/code/core/Mage/Core/Model/Log/Adapter.php +++ b/app/code/core/Mage/Core/Model/Log/Adapter.php @@ -115,7 +115,7 @@ public function setFilterDataKeys($keys) protected function _filterDebugData($debugData) { if (is_array($debugData) && is_array($this->_debugReplacePrivateDataKeys)) { - foreach (array_keys($debugData) as $key) { + foreach ($debugData as $key => $value) { if (in_array($key, $this->_debugReplacePrivateDataKeys)) { $debugData[$key] = '****'; } else { diff --git a/app/code/core/Mage/Core/Model/Url/Rewrite.php b/app/code/core/Mage/Core/Model/Url/Rewrite.php index 929f39be12c..a9bae5f2912 100644 --- a/app/code/core/Mage/Core/Model/Url/Rewrite.php +++ b/app/code/core/Mage/Core/Model/Url/Rewrite.php @@ -319,7 +319,7 @@ protected function _getQueryString() $queryParams = []; parse_str($_SERVER['QUERY_STRING'], $queryParams); $hasChanges = false; - foreach (array_keys($queryParams) as $key) { + foreach ($queryParams as $key => $value) { if (substr($key, 0, 3) === '___') { unset($queryParams[$key]); $hasChanges = true; diff --git a/app/code/core/Mage/Core/Model/Url/Rewrite/Request.php b/app/code/core/Mage/Core/Model/Url/Rewrite/Request.php index f6c14bf4b9a..80bf9ce24de 100644 --- a/app/code/core/Mage/Core/Model/Url/Rewrite/Request.php +++ b/app/code/core/Mage/Core/Model/Url/Rewrite/Request.php @@ -306,7 +306,7 @@ protected function _getQueryString() $queryParams = []; parse_str($_SERVER['QUERY_STRING'], $queryParams); $hasChanges = false; - foreach (array_keys($queryParams) as $key) { + foreach ($queryParams as $key => $value) { if (substr($key, 0, 3) === '___') { unset($queryParams[$key]); $hasChanges = true; diff --git a/app/code/core/Mage/Customer/Model/Address/Api.php b/app/code/core/Mage/Customer/Model/Address/Api.php index 9f779558882..63120a58f38 100644 --- a/app/code/core/Mage/Customer/Model/Address/Api.php +++ b/app/code/core/Mage/Customer/Model/Address/Api.php @@ -55,7 +55,7 @@ public function items($customerId) $row[$attributeAlias] = $data[$attributeCode] ?? null; } - foreach (array_keys($this->getAllowedAttributes($address)) as $attributeCode) { + foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { if (isset($data[$attributeCode])) { $row[$attributeCode] = $data[$attributeCode]; } @@ -89,7 +89,7 @@ public function create($customerId, $addressData) $address = Mage::getModel('customer/address'); - foreach (array_keys($this->getAllowedAttributes($address)) as $attributeCode) { + foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { if (isset($addressData[$attributeCode])) { $address->setData($attributeCode, $addressData[$attributeCode]); } @@ -141,7 +141,7 @@ public function info($addressId) $result[$attributeAlias] = $address->getData($attributeCode); } - foreach (array_keys($this->getAllowedAttributes($address)) as $attributeCode) { + foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { $result[$attributeCode] = $address->getData($attributeCode); } @@ -169,7 +169,7 @@ public function update($addressId, $addressData) $this->_fault('not_exists'); } - foreach (array_keys($this->getAllowedAttributes($address)) as $attributeCode) { + foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { if (isset($addressData[$attributeCode])) { $address->setData($attributeCode, $addressData[$attributeCode]); } diff --git a/app/code/core/Mage/Customer/Model/Address/Api/V2.php b/app/code/core/Mage/Customer/Model/Address/Api/V2.php index 901b932eef7..8616fec57a1 100644 --- a/app/code/core/Mage/Customer/Model/Address/Api/V2.php +++ b/app/code/core/Mage/Customer/Model/Address/Api/V2.php @@ -40,7 +40,7 @@ public function create($customerId, $addressData) $address = Mage::getModel('customer/address'); - foreach (array_keys($this->getAllowedAttributes($address)) as $attributeCode) { + foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { if (isset($addressData->$attributeCode)) { $address->setData($attributeCode, $addressData->$attributeCode); } @@ -92,7 +92,7 @@ public function info($addressId) $result[$attributeAlias] = $address->getData($attributeCode); } - foreach (array_keys($this->getAllowedAttributes($address)) as $attributeCode) { + foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { $result[$attributeCode] = $address->getData($attributeCode); } @@ -120,7 +120,7 @@ public function update($addressId, $addressData) $this->_fault('not_exists'); } - foreach (array_keys($this->getAllowedAttributes($address)) as $attributeCode) { + foreach ($this->getAllowedAttributes($address) as $attributeCode => $attribute) { if (isset($addressData->$attributeCode)) { $address->setData($attributeCode, $addressData->$attributeCode); } diff --git a/app/code/core/Mage/Customer/Model/Customer/Api.php b/app/code/core/Mage/Customer/Model/Customer/Api.php index f8daaa27a89..16853c6c60e 100644 --- a/app/code/core/Mage/Customer/Model/Customer/Api.php +++ b/app/code/core/Mage/Customer/Model/Customer/Api.php @@ -87,7 +87,7 @@ public function info($customerId, $attributes = null) $result[$attributeAlias] = $customer->getData($attributeCode); } - foreach (array_keys($this->getAllowedAttributes($customer, $attributes)) as $attributeCode) { + foreach ($this->getAllowedAttributes($customer, $attributes) as $attributeCode => $attribute) { $result[$attributeCode] = $customer->getData($attributeCode); } @@ -121,7 +121,7 @@ public function items($filters) foreach ($this->_mapAttributes as $attributeAlias => $attributeCode) { $row[$attributeAlias] = $data[$attributeCode] ?? null; } - foreach (array_keys($this->getAllowedAttributes($customer)) as $attributeCode) { + foreach ($this->getAllowedAttributes($customer) as $attributeCode => $attribute) { if (isset($data[$attributeCode])) { $row[$attributeCode] = $data[$attributeCode]; } @@ -149,7 +149,7 @@ public function update($customerId, $customerData) $this->_fault('not_exists'); } - foreach (array_keys($this->getAllowedAttributes($customer)) as $attributeCode) { + foreach ($this->getAllowedAttributes($customer) as $attributeCode => $attribute) { if (isset($customerData[$attributeCode])) { $customer->setData($attributeCode, $customerData[$attributeCode]); } diff --git a/app/code/core/Mage/Dataflow/Model/Batch.php b/app/code/core/Mage/Dataflow/Model/Batch.php index 1235b8f468f..1f727062e73 100644 --- a/app/code/core/Mage/Dataflow/Model/Batch.php +++ b/app/code/core/Mage/Dataflow/Model/Batch.php @@ -92,12 +92,12 @@ public function getFieldList() */ public function parseFieldList($row) { - foreach (array_keys($row) as $fieldName) { + foreach ($row as $fieldName => $value) { if (!in_array($fieldName, $this->_fieldList)) { $this->_fieldList[$fieldName] = $fieldName; } } - unset($fieldName, $row); + unset($fieldName, $value, $row); } /** diff --git a/app/code/core/Mage/Dataflow/Model/Session/Parser/Csv.php b/app/code/core/Mage/Dataflow/Model/Session/Parser/Csv.php index fdf30b8c5f6..1a15c400f15 100644 --- a/app/code/core/Mage/Dataflow/Model/Session/Parser/Csv.php +++ b/app/code/core/Mage/Dataflow/Model/Session/Parser/Csv.php @@ -47,7 +47,7 @@ public function parse() $fields = $line; continue; } else { - foreach (array_keys($line) as $j) { + foreach ($line as $j => $f) { $fields[$j] = 'column' . ($j + 1); } } diff --git a/app/code/core/Mage/Eav/Model/Entity/Abstract.php b/app/code/core/Mage/Eav/Model/Entity/Abstract.php index 01c39e4c918..25c93a56c2e 100644 --- a/app/code/core/Mage/Eav/Model/Entity/Abstract.php +++ b/app/code/core/Mage/Eav/Model/Entity/Abstract.php @@ -1594,7 +1594,7 @@ public function delete($object) ]; $this->_getWriteAdapter()->delete($this->getEntityTable(), $where); $this->loadAllAttributes($object); - foreach (array_keys($this->getAttributesByTable()) as $table) { + foreach ($this->getAttributesByTable() as $table => $attributes) { $this->_getWriteAdapter()->delete($table, $where); } } catch (Exception $e) { diff --git a/app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php b/app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php index 1ecb2e87b92..91b578e810a 100644 --- a/app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php +++ b/app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php @@ -790,7 +790,7 @@ protected function _prepareExport() '_custom_option_row_sku', '_custom_option_row_sort' ]; - foreach (array_keys($this->_storeIdToCode) as &$storeId) { + foreach ($this->_storeIdToCode as $storeId => &$storeCode) { $skip = false; $options = Mage::getResourceModel('catalog/product_option_collection') ->reset() @@ -961,7 +961,7 @@ protected function _prepareExport() $dataRow = array_merge($dataRow, array_shift($configurableData[$productId])); } if (!empty($rowMultiselects[$productId][$storeId])) { - foreach (array_keys($rowMultiselects[$productId][$storeId]) as $attrKey) { + foreach ($rowMultiselects[$productId][$storeId] as $attrKey => $attrVal) { if (isset($rowMultiselects[$productId][$storeId][$attrKey])) { $dataRow[$attrKey] = array_shift($rowMultiselects[$productId][$storeId][$attrKey]); } @@ -1039,7 +1039,7 @@ protected function _prepareExport() $dataRow = array_merge($dataRow, array_shift($configurableData[$productId])); } if (!empty($rowMultiselects[$productId][$storeId])) { - foreach (array_keys($rowMultiselects[$productId][$storeId]) as $attrKey) { + foreach ($rowMultiselects[$productId][$storeId] as $attrKey => $attrVal) { if (isset($rowMultiselects[$productId][$storeId][$attrKey])) { $dataRow[$attrKey] = array_shift($rowMultiselects[$productId][$storeId][$attrKey]); } diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php index 5fc9083546d..6c1771b734e 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php @@ -547,7 +547,7 @@ public function getEntityTypeCode() public function getRowScope(array $rowData) { $foundOptions = false; - foreach (array_keys($this->_multiSelectAttributes) as $attrCode) { + foreach ($this->_multiSelectAttributes as $attrCode => $attribute) { if ($rowData[$attrCode]) { $foundOptions = true; } diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php index 914c5be124f..0a4cf80d21e 100644 --- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php +++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php @@ -1099,7 +1099,7 @@ protected function _saveCustomOptions() if ($productIds) { // update product entity table to show that product has options $customOptionsProducts = $customOptions['product_id']; - foreach (array_keys($customOptionsProducts) as $key) { + foreach ($customOptionsProducts as $key => $value) { if (!in_array($key, $productIds)) { unset($customOptionsProducts[$key]); } diff --git a/app/code/core/Mage/Index/Model/Event.php b/app/code/core/Mage/Index/Model/Event.php index d4dc4468a17..2035a5be359 100644 --- a/app/code/core/Mage/Index/Model/Event.php +++ b/app/code/core/Mage/Index/Model/Event.php @@ -157,7 +157,7 @@ protected function _mergeNewDataRecursive($previous, $current) return $previous; } - foreach (array_keys($previous) as $key) { + foreach ($previous as $key => $value) { if (array_key_exists($key, $current) && !is_null($current[$key]) && is_array($previous[$key])) { if (!is_string($key) || is_array($current[$key])) { $current[$key] = $this->_mergeNewDataRecursive($previous[$key], $current[$key]); diff --git a/app/code/core/Mage/Install/Block/Db/Main.php b/app/code/core/Mage/Install/Block/Db/Main.php index 25791d2f5f8..9f0789c1ea3 100644 --- a/app/code/core/Mage/Install/Block/Db/Main.php +++ b/app/code/core/Mage/Install/Block/Db/Main.php @@ -77,7 +77,7 @@ public function getDatabaseBlock($type) public function getDatabaseBlocks() { $databases = []; - foreach (array_keys($this->_databases) as $type) { + foreach ($this->_databases as $type => $blockData) { $databases[] = $this->getDatabaseBlock($type); } return $databases; diff --git a/app/code/core/Mage/Install/Model/Installer/Console.php b/app/code/core/Mage/Install/Model/Installer/Console.php index 7c31a5007ab..033d8db36a4 100644 --- a/app/code/core/Mage/Install/Model/Installer/Console.php +++ b/app/code/core/Mage/Install/Model/Installer/Console.php @@ -155,7 +155,7 @@ public function setArgs($args = null) /** * Set args values */ - foreach (array_keys($this->_getOptions()) as $name) { + foreach ($this->_getOptions() as $name => $option) { $this->_args[$name] = $args[$name] ?? ''; } diff --git a/app/code/core/Mage/Install/Model/Installer/Db/Abstract.php b/app/code/core/Mage/Install/Model/Installer/Db/Abstract.php index 33b6de0c2ea..40155d07e4a 100644 --- a/app/code/core/Mage/Install/Model/Installer/Db/Abstract.php +++ b/app/code/core/Mage/Install/Model/Installer/Db/Abstract.php @@ -136,7 +136,7 @@ public function getRequiredExtensions() { $extensions = []; $configExt = (array)Mage::getConfig()->getNode(sprintf('install/databases/%s/extensions', $this->getModel())); - foreach (array_keys($configExt) as $name) { + foreach ($configExt as $name => $value) { $extensions[] = $name; } return $extensions; diff --git a/app/code/core/Mage/Page/Block/Template/Links.php b/app/code/core/Mage/Page/Block/Template/Links.php index aacfd69b27e..b52e2f367eb 100644 --- a/app/code/core/Mage/Page/Block/Template/Links.php +++ b/app/code/core/Mage/Page/Block/Template/Links.php @@ -242,7 +242,7 @@ protected function _getNewPosition($position = 0) } } else { $position = 0; - foreach (array_keys($this->_links) as $k) { + foreach ($this->_links as $k => $v) { $position = $k; } $position += 10; diff --git a/app/code/core/Mage/Paygate/Model/Authorizenet.php b/app/code/core/Mage/Paygate/Model/Authorizenet.php index c32a8b69385..5659e2caac3 100644 --- a/app/code/core/Mage/Paygate/Model/Authorizenet.php +++ b/app/code/core/Mage/Paygate/Model/Authorizenet.php @@ -1475,7 +1475,7 @@ protected function _addTransaction( $payment->setTransactionAdditionalInfo($key, $value); } $transaction = $payment->addTransaction($transactionType, null, false, $message); - foreach (array_keys($transactionDetails) as $key) { + foreach ($transactionDetails as $key => $value) { $payment->unsetData($key); } $payment->unsLastTransId(); diff --git a/app/code/core/Mage/Payment/Block/Form/Cc.php b/app/code/core/Mage/Payment/Block/Form/Cc.php index 08a12b4c037..5435e7f4a75 100644 --- a/app/code/core/Mage/Payment/Block/Form/Cc.php +++ b/app/code/core/Mage/Payment/Block/Form/Cc.php @@ -47,7 +47,7 @@ public function getCcAvailableTypes() $availableTypes = $method->getConfigData('cctypes'); if ($availableTypes) { $availableTypes = explode(',', $availableTypes); - foreach (array_keys($types) as $code) { + foreach ($types as $code => $name) { if (!in_array($code, $availableTypes)) { unset($types[$code]); } diff --git a/app/code/core/Mage/Payment/Helper/Data.php b/app/code/core/Mage/Payment/Helper/Data.php index fed881ddeae..a7f9071c590 100644 --- a/app/code/core/Mage/Payment/Helper/Data.php +++ b/app/code/core/Mage/Payment/Helper/Data.php @@ -67,7 +67,7 @@ public function getMethodInstance($code) public function getStoreMethods($store = null, $quote = null) { $res = []; - foreach (array_keys($this->getPaymentMethods($store)) as $code) { + foreach ($this->getPaymentMethods($store) as $code => $methodConfig) { $prefix = self::XML_PATH_PAYMENT_METHODS . '/' . $code . '/'; if (!$model = Mage::getStoreConfig($prefix . 'model', $store)) { continue; @@ -166,7 +166,7 @@ public function getBillingAgreementMethods($store = null, $quote = null) public function getRecurringProfileMethods($store = null) { $result = []; - foreach (array_keys($this->getPaymentMethods($store)) as $code) { + foreach ($this->getPaymentMethods($store) as $code => $data) { $paymentMethodModelClassName = $this->getMethodModelClassName($code); if (!$paymentMethodModelClassName) { continue; @@ -244,7 +244,7 @@ public function getPaymentMethodList($sorted = true, $asLabelValue = false, $wit } if ($asLabelValue) { $labelValues = []; - foreach (array_keys($methods) as $code) { + foreach ($methods as $code => $title) { $labelValues[$code] = []; } foreach ($methods as $code => $title) { diff --git a/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement.php b/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement.php index fca1a3d661e..ec75245e7e2 100644 --- a/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement.php +++ b/app/code/core/Mage/Paypal/Model/Resource/Report/Settlement.php @@ -58,7 +58,7 @@ protected function _afterSave(Mage_Core_Model_Abstract $object) /** @var Mage_Core_Model_Date $date */ $date = Mage::getSingleton('core/date'); - foreach (array_keys($rows) as $key) { + foreach ($rows as $key => $row) { /* * Converting dates */ diff --git a/app/code/core/Mage/Reports/Model/Totals.php b/app/code/core/Mage/Reports/Model/Totals.php index 6b98422fdee..33f899cc705 100644 --- a/app/code/core/Mage/Reports/Model/Totals.php +++ b/app/code/core/Mage/Reports/Model/Totals.php @@ -47,7 +47,7 @@ public function countTotals($grid, $from, $to) } $data = $item->getData(); - foreach (array_keys($columns) as $field) { + foreach ($columns as $field => $a) { if ($field !== '') { $columns[$field]['value'] += $data[$field] ?? 0; } diff --git a/app/code/core/Mage/Rule/Model/Action/Abstract.php b/app/code/core/Mage/Rule/Model/Action/Abstract.php index d8cb87fb7f4..a810922d2f7 100644 --- a/app/code/core/Mage/Rule/Model/Action/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Action/Abstract.php @@ -52,11 +52,11 @@ public function __construct() parent::__construct(); $this->loadAttributeOptions()->loadOperatorOptions()->loadValueOptions(); - foreach (array_keys($this->getAttributeOption()) as $attr) { + foreach ($this->getAttributeOption() as $attr => $dummy) { $this->setAttribute($attr); break; } - foreach (array_keys($this->getOperatorOption()) as $operator) { + foreach ($this->getOperatorOption() as $operator => $dummy) { $this->setOperator($operator); break; } diff --git a/app/code/core/Mage/Rule/Model/Condition/Abstract.php b/app/code/core/Mage/Rule/Model/Condition/Abstract.php index e31fbdda29c..d2e67c86270 100644 --- a/app/code/core/Mage/Rule/Model/Condition/Abstract.php +++ b/app/code/core/Mage/Rule/Model/Condition/Abstract.php @@ -92,13 +92,13 @@ public function __construct() $this->loadAttributeOptions()->loadOperatorOptions()->loadValueOptions(); if ($options = $this->getAttributeOptions()) { - foreach (array_keys($options) as $attr) { + foreach ($options as $attr => $dummy) { $this->setAttribute($attr); break; } } if ($options = $this->getOperatorOptions()) { - foreach (array_keys($options) as $operator) { + foreach ($options as $operator => $dummy) { $this->setOperator($operator); break; } @@ -503,7 +503,7 @@ public function getTypeElementHtml() public function getAttributeElement() { if (is_null($this->getAttribute())) { - foreach (array_keys($this->getAttributeOption()) as $k) { + foreach ($this->getAttributeOption() as $k => $v) { $this->setAttribute($k); break; } diff --git a/app/code/core/Mage/Rule/Model/Condition/Combine.php b/app/code/core/Mage/Rule/Model/Condition/Combine.php index 1d9b0093d13..79d4e693c38 100644 --- a/app/code/core/Mage/Rule/Model/Condition/Combine.php +++ b/app/code/core/Mage/Rule/Model/Condition/Combine.php @@ -95,7 +95,7 @@ public function __construct() $this->loadAggregatorOptions(); if ($options = $this->getAggregatorOptions()) { - foreach (array_keys($options) as $aggregator) { + foreach ($options as $aggregator => $dummy) { $this->setAggregator($aggregator); break; } diff --git a/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php b/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php index 713bee21bab..52bf6a9b347 100644 --- a/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php +++ b/app/code/core/Mage/Sales/Block/Adminhtml/Customer/Edit/Tab/Agreement.php @@ -125,7 +125,7 @@ protected function _prepareColumns() { $result = parent::_prepareColumns(); - foreach (array_keys($this->_columns) as $key) { + foreach ($this->_columns as $key => $value) { if (in_array($key, $this->_columnsToRemove)) { unset($this->_columns[$key]); } diff --git a/app/code/core/Mage/Sales/Model/Resource/Report/Order/Createdat.php b/app/code/core/Mage/Sales/Model/Resource/Report/Order/Createdat.php index a9971351972..323ce47e00f 100644 --- a/app/code/core/Mage/Sales/Model/Resource/Report/Order/Createdat.php +++ b/app/code/core/Mage/Sales/Model/Resource/Report/Order/Createdat.php @@ -230,7 +230,7 @@ protected function _aggregateByField($aggregationField, $from, $to) $adapter->query($select->insertFromSelect($this->getMainTable(), array_keys($columns))); // setup all columns to select SUM() except period, store_id and order_status - foreach (array_keys($columns) as $k) { + foreach ($columns as $k => $v) { $columns[$k] = new Zend_Db_Expr('SUM(' . $k . ')'); } $columns['period'] = 'period'; diff --git a/app/code/core/Mage/Sales/Model/Resource/Sale/Collection.php b/app/code/core/Mage/Sales/Model/Resource/Sale/Collection.php index f2972e84cc9..1bf6ed99bf1 100644 --- a/app/code/core/Mage/Sales/Model/Resource/Sale/Collection.php +++ b/app/code/core/Mage/Sales/Model/Resource/Sale/Collection.php @@ -182,7 +182,7 @@ public function load($printQuery = false, $logQuery = false) ->setWebsiteId(Mage::app()->getStore($storeId)->getWebsiteId()) ->setAvgNormalized($v['avgsale'] * $v['num_orders']); $this->_items[$storeId] = $storeObject; - foreach (array_keys($this->_totals) as $key) { + foreach ($this->_totals as $key => $value) { $this->_totals[$key] += $storeObject->getData($key); } } diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php index 9525a968c57..43d089aa854 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php @@ -183,7 +183,7 @@ $select->from(['e' => $this->getTable('sales_order_entity')]); $attributeIds = []; -foreach (array_keys($attributes) as $code) { +foreach ($attributes as $code => $params) { $attributes[$code] = $installer->getAttribute($orderEntityTypeId, $code); if ($attributes[$code]['backend_type'] != 'static') { $select->joinLeft( diff --git a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php index 69722481f54..3e9e34ea693 100644 --- a/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php +++ b/app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php @@ -46,7 +46,7 @@ "); /* get order_payment attribute codes*/ -foreach (array_keys($attributesIds) as $attributeCode) { +foreach ($attributesIds as $attributeCode => $attributeId) { $attributesIds[$attributeCode] = $connection->fetchOne(" SELECT attribute_id FROM {$this->getTable('eav_attribute')} diff --git a/app/code/core/Mage/Shipping/Model/Rate/Result.php b/app/code/core/Mage/Shipping/Model/Rate/Result.php index bc7ad148a12..fa06daacb29 100644 --- a/app/code/core/Mage/Shipping/Model/Rate/Result.php +++ b/app/code/core/Mage/Shipping/Model/Rate/Result.php @@ -180,7 +180,7 @@ public function sortRatesByPrice() natsort($tmp); - foreach (array_keys($tmp) as $i) { + foreach ($tmp as $i => $price) { $result[] = $this->_rates[$i]; } diff --git a/app/code/core/Mage/Tag/Helper/Data.php b/app/code/core/Mage/Tag/Helper/Data.php index a2de68080cc..c86d4d5eee1 100644 --- a/app/code/core/Mage/Tag/Helper/Data.php +++ b/app/code/core/Mage/Tag/Helper/Data.php @@ -73,7 +73,7 @@ public function extractTags($tagNamesInString) */ public function cleanTags(array $tagNamesArr) { - foreach (array_keys($tagNamesArr) as $key) { + foreach ($tagNamesArr as $key => $tagName) { $tagNamesArr[$key] = trim($tagNamesArr[$key], '\''); $tagNamesArr[$key] = trim($tagNamesArr[$key]); if ($tagNamesArr[$key] == '') { diff --git a/app/code/core/Mage/Tag/controllers/IndexController.php b/app/code/core/Mage/Tag/controllers/IndexController.php index 833837c75b6..54b26c441f7 100644 --- a/app/code/core/Mage/Tag/controllers/IndexController.php +++ b/app/code/core/Mage/Tag/controllers/IndexController.php @@ -99,7 +99,7 @@ protected function _extractTags($tagNamesInString) */ protected function _cleanTags(array $tagNamesArr) { - foreach (array_keys($tagNamesArr) as $key) { + foreach ($tagNamesArr as $key => $tagName) { $tagNamesArr[$key] = trim($tagNamesArr[$key], '\''); $tagNamesArr[$key] = trim($tagNamesArr[$key]); if ($tagNamesArr[$key] == '') { diff --git a/app/code/core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php b/app/code/core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php index f6ed065e028..ed49099010c 100644 --- a/app/code/core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php +++ b/app/code/core/Mage/Weee/Model/Attribute/Backend/Weee/Tax.php @@ -74,7 +74,7 @@ public function afterLoad($object) { $data = $this->_getResource()->loadProductData($object, $this->getAttribute()); - foreach (array_keys($data) as $i) { + foreach ($data as $i => $row) { if ($data[$i]['website_id'] == 0) { $rate = Mage::app()->getStore()->getBaseCurrency()->getRate(Mage::app()->getBaseCurrencyCode()); if ($rate) { diff --git a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Attribute/Edit/AttributeForm.php b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Attribute/Edit/AttributeForm.php index 1344cfc1a92..9683e4322cd 100644 --- a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Attribute/Edit/AttributeForm.php +++ b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Attribute/Edit/AttributeForm.php @@ -45,7 +45,7 @@ public function getData(FixtureInterface $fixture = null, Element $element = nul { $data = []; if ($fixture === null) { - foreach (array_keys($this->tabs) as $tabName) { + foreach ($this->tabs as $tabName => $tab) { $this->openTab($tabName); $tabData = $this->getTabElement($tabName)->getDataFormTab(); $data = array_merge($data, $tabData); diff --git a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Edit/Tab/Prices.php b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Edit/Tab/Prices.php index 657f84a8239..3346dcc17a8 100644 --- a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Edit/Tab/Prices.php +++ b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/Edit/Tab/Prices.php @@ -54,7 +54,7 @@ class Prices extends Tab public function fillFormTab(array $fields, Element $element = null) { $context = $element ? $element : $this->_rootElement; - foreach (array_keys($this->childrenForm) as $key) { + foreach ($this->childrenForm as $key => $value) { if (isset($fields[$key])) { $this->fillOptionsPrices([$key => $fields[$key]], $context); unset($fields[$key]); @@ -91,7 +91,7 @@ public function getDataFormTab($fields = null, Element $element = null) { $result = []; $context = $element ? $element : $this->_rootElement; - foreach (array_keys($this->childrenForm) as $key) { + foreach ($this->childrenForm as $key => $value) { if (isset($fields[$key])) { $result[$key] = $this->getOptionsPrices([$key => $fields[$key]], $context); unset($fields[$key]); diff --git a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/ProductForm.php b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/ProductForm.php index 565b823b7c5..584a8f25fbc 100644 --- a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/ProductForm.php +++ b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Catalog/Product/ProductForm.php @@ -341,7 +341,7 @@ public function getRequireNoticeAttributes(FixtureInterface $product) { $data = []; $tabs = $this->getFieldsByTabs($product); - foreach (array_keys($tabs) as $tabName) { + foreach ($tabs as $tabName => $fields) { $tab = $this->getTabElement($tabName); $this->openTab($tabName); $errors = $tab->getRequireNoticeMessages(); diff --git a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Widget/FormTabs.php b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Widget/FormTabs.php index a0c24f0c42d..8d9596cda76 100644 --- a/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Widget/FormTabs.php +++ b/dev/tests/functional/tests/app/Mage/Adminhtml/Test/Block/Widget/FormTabs.php @@ -135,7 +135,7 @@ protected function fillTabs(array $tabs, Element $element = null) */ protected function fillMissedFields() { - foreach (array_keys($this->tabs) as $tabName) { + foreach ($this->tabs as $tabName => $tabData) { $tabElement = $this->getTabElement($tabName); if ($this->openTab($tabName)) { $mapping = $tabElement->dataMapping($this->unassignedFields); @@ -174,7 +174,7 @@ public function getData(FixtureInterface $fixture = null, Element $element = nul $data = []; if (null === $fixture) { - foreach (array_keys($this->tabs) as $tabName) { + foreach ($this->tabs as $tabName => $tab) { $this->openTab($tabName); $tabData = $this->getTabElement($tabName)->getDataFormTab(); $data = array_merge($data, $tabData); diff --git a/dev/tests/functional/tests/app/Mage/Bundle/Test/Handler/Curl.php b/dev/tests/functional/tests/app/Mage/Bundle/Test/Handler/Curl.php index eb79bfc90ef..e4777d9f973 100644 --- a/dev/tests/functional/tests/app/Mage/Bundle/Test/Handler/Curl.php +++ b/dev/tests/functional/tests/app/Mage/Bundle/Test/Handler/Curl.php @@ -146,7 +146,7 @@ protected function prepareBundleSelections(array $bundleData) */ protected function prepareItemSelectionData(array $selections, array $products) { - foreach (array_keys($selections) as $key) { + foreach ($selections as $key => $selection) { $selections[$key]['product_id'] = $products[$key]->getId(); unset($selections[$key]['sku']); $selections[$key]['delete'] = ''; @@ -163,7 +163,7 @@ protected function prepareItemSelectionData(array $selections, array $products) */ protected function prepareBundleOptions(array $bundleData) { - foreach (array_keys($bundleData) as $key) { + foreach ($bundleData as $key => $option) { $bundleData[$key] = array_intersect_key($bundleData[$key], array_flip($this->optionsFields)); $bundleData[$key]['delete'] = ''; } diff --git a/dev/tests/functional/tests/app/Mage/Catalog/Test/TestStep/UpdateConfigurableProductStep/DeleteOptionsSubStep.php b/dev/tests/functional/tests/app/Mage/Catalog/Test/TestStep/UpdateConfigurableProductStep/DeleteOptionsSubStep.php index 16d05ab359c..6b18d2b8ea3 100644 --- a/dev/tests/functional/tests/app/Mage/Catalog/Test/TestStep/UpdateConfigurableProductStep/DeleteOptionsSubStep.php +++ b/dev/tests/functional/tests/app/Mage/Catalog/Test/TestStep/UpdateConfigurableProductStep/DeleteOptionsSubStep.php @@ -86,7 +86,7 @@ protected function searchKeysForOption($optionIndex) { $keys = []; $originalProductAssignedProducts = $this->getOriginalProductAssignedProducts(); - foreach (array_keys($originalProductAssignedProducts) as $key) { + foreach ($originalProductAssignedProducts as $key => $product) { if (strpos($key, 'option_key_' . $optionIndex) !== false) { $keys[] = $key; } diff --git a/dev/tests/functional/tests/app/Mage/Customer/Test/Handler/Customer/Curl.php b/dev/tests/functional/tests/app/Mage/Customer/Test/Handler/Customer/Curl.php index 23d27ff801b..68f2f85b69a 100644 --- a/dev/tests/functional/tests/app/Mage/Customer/Test/Handler/Customer/Curl.php +++ b/dev/tests/functional/tests/app/Mage/Customer/Test/Handler/Customer/Curl.php @@ -131,7 +131,7 @@ public function persist(FixtureInterface $customer = null) */ protected function checkForUpdateData(array $data) { - foreach (array_keys($data) as $key) { + foreach ($data as $key => $field) { if (in_array($key, $this->updatingFields)) { return true; } diff --git a/dev/tests/functional/tests/app/Mage/Weee/Test/Constraint/AssertFptApplied.php b/dev/tests/functional/tests/app/Mage/Weee/Test/Constraint/AssertFptApplied.php index baf99e0e016..c1b61df6d23 100644 --- a/dev/tests/functional/tests/app/Mage/Weee/Test/Constraint/AssertFptApplied.php +++ b/dev/tests/functional/tests/app/Mage/Weee/Test/Constraint/AssertFptApplied.php @@ -145,7 +145,7 @@ protected function clearShoppingCart() protected function getPrices() { $actualPrices = []; - foreach (array_keys($this->expectedPrices) as $priceType) { + foreach ($this->expectedPrices as $priceType => $prices) { $actualPrices[$priceType] = $this->{'get' . ucfirst($priceType) . 'Price'}(); } diff --git a/lib/Varien/Convert/Parser/Csv.php b/lib/Varien/Convert/Parser/Csv.php index 4550d155691..f857c3b85a8 100644 --- a/lib/Varien/Convert/Parser/Csv.php +++ b/lib/Varien/Convert/Parser/Csv.php @@ -44,7 +44,7 @@ public function parse() $fields = $line; continue; } else { - foreach (array_keys($line) as $j) { + foreach ($line as $j => $f) { $fields[$j] = 'column' . ($j + 1); } } @@ -87,7 +87,7 @@ public function parseTest() $fields = $line; continue; } else { - foreach (array_keys($line) as $j) { + foreach ($line as $j => $f) { $fields[$j] = 'column' . ($j + 1); } } diff --git a/lib/Varien/Db/Statement/Pdo/Mysql.php b/lib/Varien/Db/Statement/Pdo/Mysql.php index d5f83882237..b23cb8435fa 100644 --- a/lib/Varien/Db/Statement/Pdo/Mysql.php +++ b/lib/Varien/Db/Statement/Pdo/Mysql.php @@ -33,7 +33,7 @@ public function _executeWithBinding(array $params) { // Check whether we deal with named bind $isPositionalBind = true; - foreach (array_keys($params) as $k) { + foreach ($params as $k => $v) { if (!is_int($k)) { $isPositionalBind = false; break; diff --git a/lib/Varien/Http/Adapter/Curl.php b/lib/Varien/Http/Adapter/Curl.php index 1e9fd81f16b..56e9359a23f 100644 --- a/lib/Varien/Http/Adapter/Curl.php +++ b/lib/Varien/Http/Adapter/Curl.php @@ -75,7 +75,7 @@ protected function _applyConfig() $verifyHost = isset($this->_config['verifyhost']) ? $this->_config['verifyhost'] : 0; curl_setopt($this->_getResource(), CURLOPT_SSL_VERIFYHOST, $verifyHost); - foreach (array_keys($this->_config) as $param) { + foreach ($this->_config as $param => $curlOption) { if (array_key_exists($param, $this->_allowedParams)) { curl_setopt($this->_getResource(), $this->_allowedParams[$param], $this->_config[$param]); } diff --git a/lib/Varien/Object.php b/lib/Varien/Object.php index 968d5b0fc02..bfd0f11bcff 100644 --- a/lib/Varien/Object.php +++ b/lib/Varien/Object.php @@ -292,7 +292,7 @@ public function unsetData($key = null) public function unsetOldData($key = null) { if (is_null($key)) { - foreach (array_keys($this->_oldFieldsMap) as $key) { + foreach ($this->_oldFieldsMap as $key => $newFieldName) { unset($this->_data[$key]); } } else { diff --git a/lib/Varien/Object/Cache.php b/lib/Varien/Object/Cache.php index 24047b87356..11b6cc23775 100644 --- a/lib/Varien/Object/Cache.php +++ b/lib/Varien/Object/Cache.php @@ -241,7 +241,7 @@ public function delete($idx) } if (isset($this->_objectReferences[$idx])) { - foreach (array_keys($this->_references) as $r) { + foreach ($this->_references as $r => $dummy) { unset($this->_references[$r]); } unset($this->_objectReferences[$idx]); diff --git a/phpstan.dist.baseline.neon b/phpstan.dist.baseline.neon index 21489364a42..8fd0d3944fa 100644 --- a/phpstan.dist.baseline.neon +++ b/phpstan.dist.baseline.neon @@ -3400,6 +3400,11 @@ parameters: count: 1 path: app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php + - + message: "#^Offset int\\|string on non\\-empty\\-array\\ in isset\\(\\) always exists and is not nullable\\.$#" + count: 2 + path: app/code/core/Mage/ImportExport/Model/Export/Entity/Product.php + - message: "#^Variable \\$collection might not be defined\\.$#" count: 1 From ae5df659954106e00e31925842dd2d7217240d8b Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Sat, 27 Jul 2024 19:35:14 +0200 Subject: [PATCH 03/13] Updates for 20.10.1 release --- .../Block/Sales/Order/Comments/View.php | 6 ++-- .../Block/Sales/Order/View/History.php | 6 ++-- app/code/core/Mage/Adminhtml/Helper/Sales.php | 6 ++-- app/code/core/Mage/Core/Block/Abstract.php | 6 ++-- app/code/core/Mage/Core/Helper/Abstract.php | 19 ++++++----- .../Core/Model/Security/HtmlEscapedString.php | 33 +++++++++++++++++-- app/code/core/Mage/Page/Block/Html/Header.php | 16 +++------ .../core/Mage/Page/Block/Html/Welcome.php | 4 +-- 8 files changed, 58 insertions(+), 38 deletions(-) diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Comments/View.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Comments/View.php index 42536309125..6e43ea89528 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Comments/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Comments/View.php @@ -77,9 +77,9 @@ public function canSendCommentEmail() /** * Replace links in string * - * @param array|string $data - * @param null|array $allowedTags - * @return string + * @param string|string[] $data + * @param array|null $allowedTags + * @return null|string|string[] */ public function escapeHtml($data, $allowedTags = null) { diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php index 372a968706e..cadd04f47d8 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php @@ -80,9 +80,9 @@ public function isCustomerNotificationNotApplicable(Mage_Sales_Model_Order_Statu /** * Replace links in string * - * @param array|string $data - * @param null|array $allowedTags - * @return string + * @param string|string[] $data + * @param array|null $allowedTags + * @return null|string|string[] */ public function escapeHtml($data, $allowedTags = null) { diff --git a/app/code/core/Mage/Adminhtml/Helper/Sales.php b/app/code/core/Mage/Adminhtml/Helper/Sales.php index 87a2ea7da46..8e6f84457df 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Sales.php +++ b/app/code/core/Mage/Adminhtml/Helper/Sales.php @@ -109,9 +109,9 @@ public function applySalableProductTypesFilter($collection) /** * Escape string preserving links * - * @param array|string $data - * @param null|array $allowedTags - * @return string + * @param string|string[] $data + * @param array|null $allowedTags + * @return null|string|string[] */ public function escapeHtmlWithLinks($data, $allowedTags = null) { diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index f33b14a031e..03d46faebdf 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -1185,9 +1185,9 @@ public function htmlEscape($data, $allowedTags = null) /** * Escape html entities * - * @param string|array $data - * @param array $allowedTags - * @return string + * @param string|string[] $data + * @param array|null $allowedTags + * @return null|string|string[] */ public function escapeHtml($data, $allowedTags = null) { diff --git a/app/code/core/Mage/Core/Helper/Abstract.php b/app/code/core/Mage/Core/Helper/Abstract.php index fc0580855c7..81a2d5832bd 100644 --- a/app/code/core/Mage/Core/Helper/Abstract.php +++ b/app/code/core/Mage/Core/Helper/Abstract.php @@ -178,9 +178,10 @@ public function __() } /** - * @param array $data - * @param array $allowedTags - * @return mixed + * @param string|string[] $data + * @param array|null $allowedTags + * @return null|string|string[] + * * @see self::escapeHtml() * @deprecated after 1.4.0.0-rc1 */ @@ -192,9 +193,9 @@ public function htmlEscape($data, $allowedTags = null) /** * Escape html entities * - * @param string|array $data - * @param array $allowedTags - * @return mixed + * @param string|string[] $data + * @param array|null $allowedTags + * @return null|string|string[] */ public function escapeHtml($data, $allowedTags = null) { @@ -244,7 +245,7 @@ function ($matches) { * Wrapper for standard strip_tags() function with extra functionality for html entities * * @param string $data - * @param string $allowableTags + * @param null|string|string[] $allowableTags * @param bool $escape * @return string */ @@ -320,9 +321,9 @@ public function escapeScriptIdentifiers($data) /** * Escape quotes in java script * - * @param mixed $data + * @param string|string[] $data * @param string $quote - * @return mixed + * @return string|string[] */ public function jsQuoteEscape($data, $quote = '\'') { diff --git a/app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php b/app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php index dd3c3f47632..1f3cb8a4c93 100644 --- a/app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php +++ b/app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php @@ -3,12 +3,35 @@ declare(strict_types=1); /** + * OpenMage * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available at https://opensource.org/license/osl-3-0-php + * + * @category Mage + * @package Mage_Core + * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) + * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + +/** + * Wrapper to escape value und keep the original value + * + * @category Mage + * @package Mage_Core */ class Mage_Core_Model_Security_HtmlEscapedString implements Stringable { - protected $originalValue; - protected $allowedTags; + /** + * @var string + */ + protected string $originalValue; + + /** + * @var string[]|null + */ + protected ?array $allowedTags; /** * @param string $originalValue @@ -20,6 +43,9 @@ public function __construct(string $originalValue, ?array $allowedTags = null) $this->allowedTags = $allowedTags; } + /** + * @return string + */ public function __toString(): string { return (string) Mage::helper('core')->escapeHtml( @@ -28,6 +54,9 @@ public function __toString(): string ); } + /** + * @return string + */ public function getUnescapedValue(): string { return $this->originalValue; diff --git a/app/code/core/Mage/Page/Block/Html/Header.php b/app/code/core/Mage/Page/Block/Html/Header.php index dab05f44c1f..6dc2d85bbd5 100644 --- a/app/code/core/Mage/Page/Block/Html/Header.php +++ b/app/code/core/Mage/Page/Block/Html/Header.php @@ -57,9 +57,7 @@ public function setLogo($logo_src, $logo_alt) public function getLogoSrc() { if (empty($this->_data['logo_src'])) { - $this->_data['logo_src'] = new Mage_Core_Model_Security_HtmlEscapedString( - (string) Mage::getStoreConfig('design/header/logo_src') - ); + $this->_data['logo_src'] = $this->escapeHtml((string) Mage::getStoreConfig('design/header/logo_src')); } return $this->getSkinUrl($this->_data['logo_src']); } @@ -70,9 +68,7 @@ public function getLogoSrc() public function getLogoSrcSmall() { if (empty($this->_data['logo_src_small'])) { - $this->_data['logo_src_small'] = new Mage_Core_Model_Security_HtmlEscapedString( - (string) Mage::getStoreConfig('design/header/logo_src_small') - ); + $this->_data['logo_src_small'] = $this->escapeHtml((string) Mage::getStoreConfig('design/header/logo_src_small')); } return $this->getSkinUrl($this->_data['logo_src_small']); } @@ -83,9 +79,7 @@ public function getLogoSrcSmall() public function getLogoAlt() { if (empty($this->_data['logo_alt'])) { - $this->_data['logo_alt'] = new Mage_Core_Model_Security_HtmlEscapedString( - (string) Mage::getStoreConfig('design/header/logo_alt') - ); + $this->_data['logo_alt'] = $this->escapeHtml((string) Mage::getStoreConfig('design/header/logo_alt')); } return $this->_data['logo_alt']; } @@ -103,9 +97,7 @@ public function getWelcome() if (Mage::isInstalled() && Mage::getSingleton('customer/session')->isLoggedIn()) { $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml(Mage::getSingleton('customer/session')->getCustomer()->getName())); } else { - $this->_data['welcome'] = new Mage_Core_Model_Security_HtmlEscapedString( - (string) Mage::getStoreConfig('design/header/welcome') - ); + $this->_data['welcome'] = $this->escapeHtml((string) Mage::getStoreConfig('design/header/welcome')); } } diff --git a/app/code/core/Mage/Page/Block/Html/Welcome.php b/app/code/core/Mage/Page/Block/Html/Welcome.php index 2f1e1f98238..2925d3b162b 100644 --- a/app/code/core/Mage/Page/Block/Html/Welcome.php +++ b/app/code/core/Mage/Page/Block/Html/Welcome.php @@ -44,9 +44,7 @@ protected function _toHtml() if (Mage::isInstalled() && $this->_getSession()->isLoggedIn()) { $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml($this->_getSession()->getCustomer()->getName())); } else { - $this->_data['welcome'] = new Mage_Core_Model_Security_HtmlEscapedString( - (string) Mage::getStoreConfig('design/header/welcome') - ); + $this->_data['welcome'] = $this->escapeHtml((string) Mage::getStoreConfig('design/header/welcome')); } } From e9b8c7ca011725bb0f2bea428a3ba23c34bb1f06 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Sun, 28 Jul 2024 17:41:36 +0200 Subject: [PATCH 04/13] Re-add possibility to get original value --- app/Mage.php | 16 +++++++++++++++- app/code/core/Mage/Page/Block/Html/Header.php | 8 ++++---- app/code/core/Mage/Page/Block/Html/Welcome.php | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/Mage.php b/app/Mage.php index 4eed1372607..e84435ff6a3 100644 --- a/app/Mage.php +++ b/app/Mage.php @@ -433,7 +433,7 @@ public static function getStoreConfigAsInt(string $path, $store = null): int * Retrieve config flag for store by path * * @param string $path - * @param mixed $store + * @param null|string|bool|int|Mage_Core_Model_Store $store * @return bool */ public static function getStoreConfigFlag($path, $store = null) @@ -447,6 +447,20 @@ public static function getStoreConfigFlag($path, $store = null) } } + + /** + * @param string $path + * @param null|string|bool|int|Mage_Core_Model_Store $store + * @param array|null $allowedTags + * @return Mage_Core_Model_Security_HtmlEscapedString + */ + public static function getStoreConfigObject(string $path, $store = null, ?array $allowedTags = []): Mage_Core_Model_Security_HtmlEscapedString + { + $config = (string) self::getStoreConfig($path, $store); + // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation + return new Mage_Core_Model_Security_HtmlEscapedString($config, $allowedTags); + } + /** * Get base URL path by type * diff --git a/app/code/core/Mage/Page/Block/Html/Header.php b/app/code/core/Mage/Page/Block/Html/Header.php index 6dc2d85bbd5..f6b27f4992b 100644 --- a/app/code/core/Mage/Page/Block/Html/Header.php +++ b/app/code/core/Mage/Page/Block/Html/Header.php @@ -57,7 +57,7 @@ public function setLogo($logo_src, $logo_alt) public function getLogoSrc() { if (empty($this->_data['logo_src'])) { - $this->_data['logo_src'] = $this->escapeHtml((string) Mage::getStoreConfig('design/header/logo_src')); + $this->_data['logo_src'] = Mage::getStoreConfigObject('design/header/logo_src'); } return $this->getSkinUrl($this->_data['logo_src']); } @@ -68,7 +68,7 @@ public function getLogoSrc() public function getLogoSrcSmall() { if (empty($this->_data['logo_src_small'])) { - $this->_data['logo_src_small'] = $this->escapeHtml((string) Mage::getStoreConfig('design/header/logo_src_small')); + $this->_data['logo_src_small'] = Mage::getStoreConfigObject('design/header/logo_src_small'); } return $this->getSkinUrl($this->_data['logo_src_small']); } @@ -79,7 +79,7 @@ public function getLogoSrcSmall() public function getLogoAlt() { if (empty($this->_data['logo_alt'])) { - $this->_data['logo_alt'] = $this->escapeHtml((string) Mage::getStoreConfig('design/header/logo_alt')); + $this->_data['logo_alt'] = Mage::getStoreConfigObject('design/header/logo_alt'); } return $this->_data['logo_alt']; } @@ -97,7 +97,7 @@ public function getWelcome() if (Mage::isInstalled() && Mage::getSingleton('customer/session')->isLoggedIn()) { $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml(Mage::getSingleton('customer/session')->getCustomer()->getName())); } else { - $this->_data['welcome'] = $this->escapeHtml((string) Mage::getStoreConfig('design/header/welcome')); + $this->_data['welcome'] = Mage::getStoreConfigObject('design/header/welcome'); } } diff --git a/app/code/core/Mage/Page/Block/Html/Welcome.php b/app/code/core/Mage/Page/Block/Html/Welcome.php index 2925d3b162b..684e6bbb761 100644 --- a/app/code/core/Mage/Page/Block/Html/Welcome.php +++ b/app/code/core/Mage/Page/Block/Html/Welcome.php @@ -44,7 +44,7 @@ protected function _toHtml() if (Mage::isInstalled() && $this->_getSession()->isLoggedIn()) { $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml($this->_getSession()->getCustomer()->getName())); } else { - $this->_data['welcome'] = $this->escapeHtml((string) Mage::getStoreConfig('design/header/welcome')); + $this->_data['welcome'] = Mage::getStoreConfigObject('design/header/welcome'); } } From 83141ac9016c8e9ed380587264e784eae4bb721d Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Sun, 28 Jul 2024 17:53:07 +0200 Subject: [PATCH 05/13] Changed default value --- app/Mage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Mage.php b/app/Mage.php index e84435ff6a3..3cb720242de 100644 --- a/app/Mage.php +++ b/app/Mage.php @@ -454,7 +454,7 @@ public static function getStoreConfigFlag($path, $store = null) * @param array|null $allowedTags * @return Mage_Core_Model_Security_HtmlEscapedString */ - public static function getStoreConfigObject(string $path, $store = null, ?array $allowedTags = []): Mage_Core_Model_Security_HtmlEscapedString + public static function getStoreConfigObject(string $path, $store = null, ?array $allowedTags = null): Mage_Core_Model_Security_HtmlEscapedString { $config = (string) self::getStoreConfig($path, $store); // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation From dde71e27dc1dc5d09dd5243a96b22bcf15eced50 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Sun, 28 Jul 2024 18:25:29 +0200 Subject: [PATCH 06/13] Moved method to Mage_Core_Block_Abstract --- app/Mage.php | 14 -------------- app/code/core/Mage/Core/Block/Abstract.php | 13 +++++++++++++ app/code/core/Mage/Page/Block/Html/Header.php | 8 ++++---- app/code/core/Mage/Page/Block/Html/Welcome.php | 2 +- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/Mage.php b/app/Mage.php index 3cb720242de..697cf0abc74 100644 --- a/app/Mage.php +++ b/app/Mage.php @@ -447,20 +447,6 @@ public static function getStoreConfigFlag($path, $store = null) } } - - /** - * @param string $path - * @param null|string|bool|int|Mage_Core_Model_Store $store - * @param array|null $allowedTags - * @return Mage_Core_Model_Security_HtmlEscapedString - */ - public static function getStoreConfigObject(string $path, $store = null, ?array $allowedTags = null): Mage_Core_Model_Security_HtmlEscapedString - { - $config = (string) self::getStoreConfig($path, $store); - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - return new Mage_Core_Model_Security_HtmlEscapedString($config, $allowedTags); - } - /** * Get base URL path by type * diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index 03d46faebdf..d4c28d0e08c 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -1194,6 +1194,19 @@ public function escapeHtml($data, $allowedTags = null) return $this->helper('core')->escapeHtml($data, $allowedTags); } + /** + * Escape html entities + * + * @param string $data + * @param array|null $allowedTags + * @return Mage_Core_Model_Security_HtmlEscapedString + */ + public function escapeHtmlAsObject(string $data, ?array $allowedTags = null): Mage_Core_Model_Security_HtmlEscapedString + { + // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation + return new Mage_Core_Model_Security_HtmlEscapedString($data, $allowedTags); + } + /** * Wrapper for standard strip_tags() function with extra functionality for html entities * diff --git a/app/code/core/Mage/Page/Block/Html/Header.php b/app/code/core/Mage/Page/Block/Html/Header.php index f6b27f4992b..1b251001f59 100644 --- a/app/code/core/Mage/Page/Block/Html/Header.php +++ b/app/code/core/Mage/Page/Block/Html/Header.php @@ -57,7 +57,7 @@ public function setLogo($logo_src, $logo_alt) public function getLogoSrc() { if (empty($this->_data['logo_src'])) { - $this->_data['logo_src'] = Mage::getStoreConfigObject('design/header/logo_src'); + $this->_data['logo_src'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/logo_src')); } return $this->getSkinUrl($this->_data['logo_src']); } @@ -68,7 +68,7 @@ public function getLogoSrc() public function getLogoSrcSmall() { if (empty($this->_data['logo_src_small'])) { - $this->_data['logo_src_small'] = Mage::getStoreConfigObject('design/header/logo_src_small'); + $this->_data['logo_src_small'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/logo_src_small')); } return $this->getSkinUrl($this->_data['logo_src_small']); } @@ -79,7 +79,7 @@ public function getLogoSrcSmall() public function getLogoAlt() { if (empty($this->_data['logo_alt'])) { - $this->_data['logo_alt'] = Mage::getStoreConfigObject('design/header/logo_alt'); + $this->_data['logo_alt'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/logo_alt')); } return $this->_data['logo_alt']; } @@ -97,7 +97,7 @@ public function getWelcome() if (Mage::isInstalled() && Mage::getSingleton('customer/session')->isLoggedIn()) { $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml(Mage::getSingleton('customer/session')->getCustomer()->getName())); } else { - $this->_data['welcome'] = Mage::getStoreConfigObject('design/header/welcome'); + $this->_data['welcome'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/welcome')); } } diff --git a/app/code/core/Mage/Page/Block/Html/Welcome.php b/app/code/core/Mage/Page/Block/Html/Welcome.php index 684e6bbb761..b8d4308488e 100644 --- a/app/code/core/Mage/Page/Block/Html/Welcome.php +++ b/app/code/core/Mage/Page/Block/Html/Welcome.php @@ -44,7 +44,7 @@ protected function _toHtml() if (Mage::isInstalled() && $this->_getSession()->isLoggedIn()) { $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml($this->_getSession()->getCustomer()->getName())); } else { - $this->_data['welcome'] = Mage::getStoreConfigObject('design/header/welcome'); + $this->_data['welcome'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/welcome')); } } From b95a4f5a37ab68d6e61510d468276e988bc2b9e6 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Sun, 28 Jul 2024 19:05:16 +0200 Subject: [PATCH 07/13] Ignore some phpcs-ecg errors [skip ci] --- app/code/core/Mage/Core/Block/Abstract.php | 5 ++++- app/code/core/Mage/Core/Model/Layout.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index d4c28d0e08c..593d38d2324 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -165,6 +165,7 @@ abstract class Mage_Core_Block_Abstract extends Varien_Object /** * @var Varien_Object */ + // phpcs:ignore Ecg.PHP.PrivateClassMember.PrivateClassMemberError private static $_transportObject; /** @@ -524,6 +525,7 @@ public function unsetCallChild($alias, $callback, $result, $params) } Mage::helper('core/security')->validateAgainstBlockMethodBlacklist($child, $callback, $params); + // phpcs:ignore Ecg.Security.ForbiddenFunction.Found if ($result == call_user_func_array([&$child, $callback], $params)) { $this->unsetChild($alias); } @@ -863,7 +865,7 @@ public function getChildGroup($groupName, $callback = null, $skipEmptyResults = * * @param string $alias * @param string $key - * @return mixed + * @return mixed|void */ public function getChildData($alias, $key = '') { @@ -1165,6 +1167,7 @@ public function getModuleName() public function __() { $args = func_get_args(); + // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation $expr = new Mage_Core_Model_Translate_Expr(array_shift($args), $this->getModuleName()); array_unshift($args, $expr); return $this->_getApp()->getTranslator()->translate($args); diff --git a/app/code/core/Mage/Core/Model/Layout.php b/app/code/core/Mage/Core/Model/Layout.php index b71d87ce8d0..063a8848923 100644 --- a/app/code/core/Mage/Core/Model/Layout.php +++ b/app/code/core/Mage/Core/Model/Layout.php @@ -419,7 +419,7 @@ protected function _translateLayoutNode($node, &$args) * Save block in blocks registry * * @param string $name - * @param Mage_Core_Model_Layout $block + * @param Mage_Core_Block_Abstract $block * @return $this */ public function setBlock($name, $block) From 80c56432ce932b3e2a577be812e59ac000f4dcfa Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Sun, 28 Jul 2024 19:47:27 +0200 Subject: [PATCH 08/13] Added method to work with arrays --- app/code/core/Mage/Core/Block/Abstract.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index 593d38d2324..7c7d7bda821 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -1201,7 +1201,7 @@ public function escapeHtml($data, $allowedTags = null) * Escape html entities * * @param string $data - * @param array|null $allowedTags + * @param string[]|null $allowedTags * @return Mage_Core_Model_Security_HtmlEscapedString */ public function escapeHtmlAsObject(string $data, ?array $allowedTags = null): Mage_Core_Model_Security_HtmlEscapedString @@ -1210,6 +1210,24 @@ public function escapeHtmlAsObject(string $data, ?array $allowedTags = null): Ma return new Mage_Core_Model_Security_HtmlEscapedString($data, $allowedTags); } + /** + * Escape html entities + * + * @param string[] $data + * @param string[]|null $allowedTags + * @return Mage_Core_Model_Security_HtmlEscapedString[] + */ + public function escapeHtmlArrayAsObject(array $data, ?array $allowedTags = null): array + { + $result = []; + foreach ($data as $kay => $string) { + // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation + $result[$kay] = new Mage_Core_Model_Security_HtmlEscapedString($string, $allowedTags); + } + + return $result; + } + /** * Wrapper for standard strip_tags() function with extra functionality for html entities * From 9479f96dd263ff58a159c5b3875195182979e0b5 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Sun, 28 Jul 2024 19:50:38 +0200 Subject: [PATCH 09/13] Added method to work with arrays (2) --- app/code/core/Mage/Core/Block/Abstract.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index 7c7d7bda821..aada2a6ff08 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -1221,8 +1221,7 @@ public function escapeHtmlArrayAsObject(array $data, ?array $allowedTags = null) { $result = []; foreach ($data as $kay => $string) { - // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation - $result[$kay] = new Mage_Core_Model_Security_HtmlEscapedString($string, $allowedTags); + $result[$kay] = $this->escapeHtmlAsObject($string, $allowedTags); } return $result; From 7ea8042653e4aebe1c28dcc89e8c0b05fe8d1884 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Mon, 29 Jul 2024 14:52:49 +0200 Subject: [PATCH 10/13] Typo [skip ci] --- app/code/core/Mage/Core/Block/Abstract.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index aada2a6ff08..0822851f93b 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -1220,8 +1220,8 @@ public function escapeHtmlAsObject(string $data, ?array $allowedTags = null): Ma public function escapeHtmlArrayAsObject(array $data, ?array $allowedTags = null): array { $result = []; - foreach ($data as $kay => $string) { - $result[$kay] = $this->escapeHtmlAsObject($string, $allowedTags); + foreach ($data as $key => $string) { + $result[$key] = $this->escapeHtmlAsObject($string, $allowedTags); } return $result; From a3002a00859e494f2ce60194d7a6d4f04ad8f063 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Wed, 7 Aug 2024 05:53:26 +0200 Subject: [PATCH 11/13] Update app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php Co-authored-by: Ng Kiat Siong --- app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php b/app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php index 1f3cb8a4c93..e05cb8634c1 100644 --- a/app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php +++ b/app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php @@ -16,7 +16,7 @@ */ /** - * Wrapper to escape value und keep the original value + * Wrapper to escape a string value with a method to get the original string value * * @category Mage * @package Mage_Core From 10c7ac63b131e6fb35d00bb84d6ab218465dbe2e Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Wed, 7 Aug 2024 06:02:53 +0200 Subject: [PATCH 12/13] Renamed methods --- app/code/core/Mage/Core/Block/Abstract.php | 6 +++--- app/code/core/Mage/Page/Block/Html/Header.php | 8 ++++---- app/code/core/Mage/Page/Block/Html/Welcome.php | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index 0822851f93b..68a405058de 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -1204,7 +1204,7 @@ public function escapeHtml($data, $allowedTags = null) * @param string[]|null $allowedTags * @return Mage_Core_Model_Security_HtmlEscapedString */ - public function escapeHtmlAsObject(string $data, ?array $allowedTags = null): Mage_Core_Model_Security_HtmlEscapedString + public function getCoreModelSecurityHtmlEscapedString(string $data, ?array $allowedTags = null): Mage_Core_Model_Security_HtmlEscapedString { // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation return new Mage_Core_Model_Security_HtmlEscapedString($data, $allowedTags); @@ -1217,11 +1217,11 @@ public function escapeHtmlAsObject(string $data, ?array $allowedTags = null): Ma * @param string[]|null $allowedTags * @return Mage_Core_Model_Security_HtmlEscapedString[] */ - public function escapeHtmlArrayAsObject(array $data, ?array $allowedTags = null): array + public function getCoreModelSecurityHtmlArrayEscapedString(array $data, ?array $allowedTags = null): array { $result = []; foreach ($data as $key => $string) { - $result[$key] = $this->escapeHtmlAsObject($string, $allowedTags); + $result[$key] = $this->getCoreModelSecurityHtmlEscapedString($string, $allowedTags); } return $result; diff --git a/app/code/core/Mage/Page/Block/Html/Header.php b/app/code/core/Mage/Page/Block/Html/Header.php index 1b251001f59..95b2548020f 100644 --- a/app/code/core/Mage/Page/Block/Html/Header.php +++ b/app/code/core/Mage/Page/Block/Html/Header.php @@ -57,7 +57,7 @@ public function setLogo($logo_src, $logo_alt) public function getLogoSrc() { if (empty($this->_data['logo_src'])) { - $this->_data['logo_src'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/logo_src')); + $this->_data['logo_src'] = $this->getCoreModelSecurityHtmlEscapedString((string) Mage::getStoreConfig('design/header/logo_src')); } return $this->getSkinUrl($this->_data['logo_src']); } @@ -68,7 +68,7 @@ public function getLogoSrc() public function getLogoSrcSmall() { if (empty($this->_data['logo_src_small'])) { - $this->_data['logo_src_small'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/logo_src_small')); + $this->_data['logo_src_small'] = $this->getCoreModelSecurityHtmlEscapedString((string) Mage::getStoreConfig('design/header/logo_src_small')); } return $this->getSkinUrl($this->_data['logo_src_small']); } @@ -79,7 +79,7 @@ public function getLogoSrcSmall() public function getLogoAlt() { if (empty($this->_data['logo_alt'])) { - $this->_data['logo_alt'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/logo_alt')); + $this->_data['logo_alt'] = $this->getCoreModelSecurityHtmlEscapedString((string) Mage::getStoreConfig('design/header/logo_alt')); } return $this->_data['logo_alt']; } @@ -97,7 +97,7 @@ public function getWelcome() if (Mage::isInstalled() && Mage::getSingleton('customer/session')->isLoggedIn()) { $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml(Mage::getSingleton('customer/session')->getCustomer()->getName())); } else { - $this->_data['welcome'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/welcome')); + $this->_data['welcome'] = $this->getCoreModelSecurityHtmlEscapedString((string) Mage::getStoreConfig('design/header/welcome')); } } diff --git a/app/code/core/Mage/Page/Block/Html/Welcome.php b/app/code/core/Mage/Page/Block/Html/Welcome.php index b8d4308488e..8de67c28923 100644 --- a/app/code/core/Mage/Page/Block/Html/Welcome.php +++ b/app/code/core/Mage/Page/Block/Html/Welcome.php @@ -44,7 +44,7 @@ protected function _toHtml() if (Mage::isInstalled() && $this->_getSession()->isLoggedIn()) { $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml($this->_getSession()->getCustomer()->getName())); } else { - $this->_data['welcome'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/welcome')); + $this->_data['welcome'] = $this->getCoreModelSecurityHtmlEscapedString((string) Mage::getStoreConfig('design/header/welcome')); } } From 12097cc34ce65520efa9a35cf8ffe76f0ea7383a Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Mon, 26 Aug 2024 14:58:21 +0200 Subject: [PATCH 13/13] Reverted renaming, updated docblocks --- app/code/core/Mage/Core/Block/Abstract.php | 14 +++++++++----- .../Mage/Core/Model/Security/HtmlEscapedString.php | 4 ++++ app/code/core/Mage/Page/Block/Html/Header.php | 8 ++++---- app/code/core/Mage/Page/Block/Html/Welcome.php | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index 68a405058de..45adafba124 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -1198,30 +1198,34 @@ public function escapeHtml($data, $allowedTags = null) } /** - * Escape html entities + * Wrapper for escapeHtml() function with keeping original value * * @param string $data * @param string[]|null $allowedTags * @return Mage_Core_Model_Security_HtmlEscapedString + * + * @see Mage_Core_Model_Security_HtmlEscapedString::getUnescapedValue() */ - public function getCoreModelSecurityHtmlEscapedString(string $data, ?array $allowedTags = null): Mage_Core_Model_Security_HtmlEscapedString + public function escapeHtmlAsObject(string $data, ?array $allowedTags = null): Mage_Core_Model_Security_HtmlEscapedString { // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation return new Mage_Core_Model_Security_HtmlEscapedString($data, $allowedTags); } /** - * Escape html entities + * Wrapper for escapeHtml() function with keeping original value * * @param string[] $data * @param string[]|null $allowedTags * @return Mage_Core_Model_Security_HtmlEscapedString[] + * + * @see Mage_Core_Model_Security_HtmlEscapedString::getUnescapedValue() */ - public function getCoreModelSecurityHtmlArrayEscapedString(array $data, ?array $allowedTags = null): array + public function escapeHtmlArrayAsObject(array $data, ?array $allowedTags = null): array { $result = []; foreach ($data as $key => $string) { - $result[$key] = $this->getCoreModelSecurityHtmlEscapedString($string, $allowedTags); + $result[$key] = $this->escapeHtmlAsObject($string, $allowedTags); } return $result; diff --git a/app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php b/app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php index e05cb8634c1..afda0b6e9a0 100644 --- a/app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php +++ b/app/code/core/Mage/Core/Model/Security/HtmlEscapedString.php @@ -44,6 +44,8 @@ public function __construct(string $originalValue, ?array $allowedTags = null) } /** + * Get escaped html entities + * * @return string */ public function __toString(): string @@ -55,6 +57,8 @@ public function __toString(): string } /** + * Get un-escaped html entities + * * @return string */ public function getUnescapedValue(): string diff --git a/app/code/core/Mage/Page/Block/Html/Header.php b/app/code/core/Mage/Page/Block/Html/Header.php index 95b2548020f..1b251001f59 100644 --- a/app/code/core/Mage/Page/Block/Html/Header.php +++ b/app/code/core/Mage/Page/Block/Html/Header.php @@ -57,7 +57,7 @@ public function setLogo($logo_src, $logo_alt) public function getLogoSrc() { if (empty($this->_data['logo_src'])) { - $this->_data['logo_src'] = $this->getCoreModelSecurityHtmlEscapedString((string) Mage::getStoreConfig('design/header/logo_src')); + $this->_data['logo_src'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/logo_src')); } return $this->getSkinUrl($this->_data['logo_src']); } @@ -68,7 +68,7 @@ public function getLogoSrc() public function getLogoSrcSmall() { if (empty($this->_data['logo_src_small'])) { - $this->_data['logo_src_small'] = $this->getCoreModelSecurityHtmlEscapedString((string) Mage::getStoreConfig('design/header/logo_src_small')); + $this->_data['logo_src_small'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/logo_src_small')); } return $this->getSkinUrl($this->_data['logo_src_small']); } @@ -79,7 +79,7 @@ public function getLogoSrcSmall() public function getLogoAlt() { if (empty($this->_data['logo_alt'])) { - $this->_data['logo_alt'] = $this->getCoreModelSecurityHtmlEscapedString((string) Mage::getStoreConfig('design/header/logo_alt')); + $this->_data['logo_alt'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/logo_alt')); } return $this->_data['logo_alt']; } @@ -97,7 +97,7 @@ public function getWelcome() if (Mage::isInstalled() && Mage::getSingleton('customer/session')->isLoggedIn()) { $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml(Mage::getSingleton('customer/session')->getCustomer()->getName())); } else { - $this->_data['welcome'] = $this->getCoreModelSecurityHtmlEscapedString((string) Mage::getStoreConfig('design/header/welcome')); + $this->_data['welcome'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/welcome')); } } diff --git a/app/code/core/Mage/Page/Block/Html/Welcome.php b/app/code/core/Mage/Page/Block/Html/Welcome.php index 8de67c28923..b8d4308488e 100644 --- a/app/code/core/Mage/Page/Block/Html/Welcome.php +++ b/app/code/core/Mage/Page/Block/Html/Welcome.php @@ -44,7 +44,7 @@ protected function _toHtml() if (Mage::isInstalled() && $this->_getSession()->isLoggedIn()) { $this->_data['welcome'] = $this->__('Welcome, %s!', $this->escapeHtml($this->_getSession()->getCustomer()->getName())); } else { - $this->_data['welcome'] = $this->getCoreModelSecurityHtmlEscapedString((string) Mage::getStoreConfig('design/header/welcome')); + $this->_data['welcome'] = $this->escapeHtmlAsObject((string) Mage::getStoreConfig('design/header/welcome')); } }