Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rector: CQ - UnusedForeachValueToArrayKeysRector #23

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,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 {
Expand Down Expand Up @@ -324,7 +324,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
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Page/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Report/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Adminhtml/Block/Store/Switcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Urlrewrite/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Widget/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Widget/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Api2/Model/Acl/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Api2/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Product/Type/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Checkout/Model/Type/Onepage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ public function assocToXml(array $array, $rootName = '_')
<$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.');
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Layout/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Log/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Url/Rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Url/Rewrite/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions app/code/core/Mage/Customer/Model/Address/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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]);
}
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Customer/Model/Address/Api/V2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Customer/Model/Customer/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Dataflow/Model/Session/Parser/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Eav/Model/Entity/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,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;
}
Expand Down
Loading
Loading