Skip to content

Commit 84a4b31

Browse files
author
Oleksii Korshenko
authored
MAGETWO-87354: Removed each function usage #13450
2 parents 325b430 + a178ee4 commit 84a4b31

File tree

8 files changed

+86
-7
lines changed

8 files changed

+86
-7
lines changed

app/code/Magento/Catalog/Model/ResourceModel/AbstractResource.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,7 @@ public function getAttributeRawValue($entityId, $attribute, $store)
568568
}
569569

570570
if (is_array($attributesData) && sizeof($attributesData) == 1) {
571-
$_data = each($attributesData);
572-
$attributesData = $_data[1];
571+
$attributesData = array_shift($attributesData);
573572
}
574573

575574
return $attributesData === false ? false : $attributesData;

app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ public function joinTable($table, $bind, $fields = null, $cond = null, $joinType
803803
{
804804
$tableAlias = null;
805805
if (is_array($table)) {
806-
list($tableAlias, $tableName) = each($table);
806+
list($tableAlias, $tableName) = [key($table), current($table)];
807807
} else {
808808
$tableName = $table;
809809
}

dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product/CollectionTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,29 @@ public function addAttributeToSortDataProvider()
160160
]
161161
];
162162
}
163+
164+
/**
165+
* Checks a case if table for join specified as an array.
166+
*
167+
* @throws \Magento\Framework\Exception\LocalizedException
168+
*/
169+
public function testJoinTable()
170+
{
171+
$this->collection->joinTable(
172+
['alias' => 'url_rewrite'],
173+
'entity_id = entity_id',
174+
['request_path'],
175+
'{{table}}.entity_type = \'product\'',
176+
'left'
177+
);
178+
$sql = (string) $this->collection->getSelect();
179+
$productTable = $this->collection->getTable('catalog_product_entity');
180+
$urlRewriteTable = $this->collection->getTable('url_rewrite');
181+
182+
$expected = 'SELECT `e`.*, `alias`.`request_path` FROM `' . $productTable . '` AS `e`'
183+
. ' LEFT JOIN `' . $urlRewriteTable . '` AS `alias` ON (alias.entity_id =e.entity_id)'
184+
. ' AND (alias.entity_type = \'product\')';
185+
186+
self::assertContains($expected, str_replace(PHP_EOL, '', $sql));
187+
}
163188
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\ResourceModel;
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Framework\ObjectManagerInterface;
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
use PHPUnit\Framework\TestCase;
12+
13+
class ProductTest extends TestCase
14+
{
15+
/**
16+
* @var Product
17+
*/
18+
private $model;
19+
20+
/**
21+
* @var ObjectManagerInterface
22+
*/
23+
private $objectManager;
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
protected function setUp()
29+
{
30+
$this->objectManager = Bootstrap::getObjectManager();
31+
32+
$this->model = $this->objectManager->get(Product::class);
33+
}
34+
35+
/**
36+
* Checks a possibility to retrieve product raw attribute value.
37+
*
38+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
39+
*/
40+
public function testGetAttributeRawValue()
41+
{
42+
$sku = 'simple';
43+
$attribute = 'name';
44+
45+
/** @var ProductRepositoryInterface $productRepository */
46+
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
47+
$product = $productRepository->get($sku);
48+
49+
$actual = $this->model->getAttributeRawValue($product->getId(), $attribute, null);
50+
self::assertEquals($product->getName(), $actual);
51+
}
52+
}

dev/tests/static/testsuite/Magento/Test/Integrity/CircularDependencyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ protected function buildModulesDependencies()
4444
$moduleName = str_replace('/', '_', $moduleName[1]);
4545
$config = simplexml_load_file($configFile);
4646
$result = $config->xpath("/config/module/depends/module") ?: [];
47-
while (list(, $node) = each($result)) {
47+
foreach ($result as $node) {
4848
/** @var \SimpleXMLElement $node */
49-
$this->moduleDependencies[$moduleName][] = (string)$node['name'];
49+
$this->moduleDependencies[$moduleName][] = (string) $node['name'];
5050
}
5151
}
5252
}

dev/tests/static/testsuite/Magento/Test/Integrity/ComposerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ public function testComponentPathsInRoot()
394394
"If there are any component paths specified, then they must be reflected in 'replace' section"
395395
);
396396
$flat = $this->getFlatPathsInfo(self::$rootJson['extra']['component_paths']);
397-
while (list(, list($component, $path)) = each($flat)) {
397+
foreach ($flat as $item) {
398+
list($component, $path) = $item;
398399
$this->assertFileExists(
399400
self::$root . '/' . $path,
400401
"Missing or invalid component path: {$component} -> {$path}"

dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,5 +2522,6 @@
25222522
['getBunchImages', 'Magento\CatalogImportExport\Model\Import\Product'],
25232523
['_isAttributeValueEmpty', 'Magento\Catalog\Model\ResourceModel\AbstractResource'],
25242524
['var_dump', ''],
2525+
['each', ''],
25252526
['isOrderIncrementIdUsed', 'Magento\Quote\Model\ResourceModel\Quote', 'Magento\Sales\Model\OrderIncrementIdChecker::isIncrementIdUsed']
25262527
];

setup/src/Magento/Setup/Model/Installer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ public function install($request)
337337

338338
$this->log->log('Starting Magento installation:');
339339

340-
while (list(, list($message, $method, $params)) = each($script)) {
340+
foreach ($script as $item) {
341+
list($message, $method, $params) = $item;
341342
$this->log->log($message);
342343
call_user_func_array([$this, $method], $params);
343344
$this->logProgress();

0 commit comments

Comments
 (0)