Skip to content

Commit 81f85d1

Browse files
author
Stanislav Idolov
authored
ENGCOM-3339: fix: cache count() results for loops #18680
2 parents a02d4ee + e622924 commit 81f85d1

File tree

14 files changed

+19
-19
lines changed

14 files changed

+19
-19
lines changed

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/AddCompareProductsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function tearDown()
7676
{
7777
$this->cmsIndex->open();
7878
$this->cmsIndex->getLinksBlock()->openLink("Compare Products");
79-
for ($i = 1; $i <= count($this->products); $i++) {
79+
for ($i = 1, $count = count($this->products); $i <= $count; $i++) {
8080
$this->catalogProductCompare->getCompareProductsBlock()->removeProduct();
8181
}
8282
}

dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/ShoppingCartPerCustomerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function test(
9595

9696
$customers = [];
9797
$cartFixtures = [];
98-
for ($i = 0; $i < count($checkoutData); $i++) {
98+
for ($i = 0, $count = count($checkoutData); $i < $count; $i++) {
9999
$customers[$i] = $this->fixtureFactory->createByCode('customer', ['dataset' => $customerDataset]);
100100
$customers[$i]->persist();
101101

dev/tests/functional/tests/app/Magento/Multishipping/Test/TestStep/FillShippingInformationStep.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct(
5858
public function run()
5959
{
6060
$shippingMethods = [];
61-
for ($i = 0; $i < count($this->customer->getAddress()); $i++) {
61+
for ($i = 0, $count = count($this->customer->getAddress()); $i < $count; $i++) {
6262
$shippingMethods[] = $this->shippingMethod;
6363
}
6464
$this->shippingInformation->getShippingBlock()->selectShippingMethod($shippingMethods);

dev/tests/functional/tests/app/Magento/Sales/Test/Constraint/AssertProductsQtyAfterOrderCancel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function processAssert(
5252
AssertProductForm $assertProductForm,
5353
AssertConfigurableProductForm $assertConfigurableProductForm
5454
) {
55-
for ($i = 0; $i < count($order->getEntityId()['products']); $i++) {
55+
for ($i = 0, $count = count($order->getEntityId()['products']); $i < $count; $i++) {
5656
$product = $order->getEntityId()['products'][$i];
5757
$productData = $product->getData();
5858
if ($product instanceof BundleProduct) {

dev/tests/integration/testsuite/Magento/Catalog/Model/Layer/Filter/Price/AlgorithmBaseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function testPricesSegmentation($categoryId, array $entityIds, array $int
112112
$items = $model->calculateSeparators($interval);
113113
$this->assertEquals(array_keys($intervalItems), array_keys($items));
114114

115-
for ($i = 0; $i < count($intervalItems); ++$i) {
115+
for ($i = 0, $count = count($intervalItems); $i < $count; ++$i) {
116116
$this->assertInternalType('array', $items[$i]);
117117
$this->assertEquals($intervalItems[$i]['from'], $items[$i]['from']);
118118
$this->assertEquals($intervalItems[$i]['to'], $items[$i]['to']);

dev/tests/static/framework/tests/unit/testsuite/Magento/Sniffs/Translation/ConstantUsageSniffTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private function tokenizeString($fileContent)
6767
$lineNumber = 1;
6868
$tokens = token_get_all($fileContent);
6969
$snifferTokens = [];
70-
for ($i = 0; $i < count($tokens); $i++) {
70+
for ($i = 0, $count = count($tokens); $i < $count; $i++) {
7171
$content = is_array($tokens[$i]) ? $tokens[$i][1] : $tokens[$i];
7272
$snifferTokens[$i]['line'] = $lineNumber;
7373
$snifferTokens[$i]['content'] = $content;

dev/tests/static/testsuite/Magento/Test/Legacy/ObsoleteCodeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ private function _checkConstantWithClasspath($constant, $class, $replacement, $c
501501
{
502502
$classPathParts = explode('\\', $class);
503503
$classPartialPath = '';
504-
for ($i = count($classPathParts) - 1; $i >= 0; $i--) {
505-
if ($i === (count($classPathParts) - 1)) {
504+
for ($count = count($classPathParts), $i = $count - 1; $i >= 0; $i--) {
505+
if ($i === ($count - 1)) {
506506
$classPartialPath = $classPathParts[$i] . $classPartialPath;
507507
} else {
508508
$classPartialPath = $classPathParts[$i] . '\\' . $classPartialPath;

lib/internal/Magento/Framework/App/Test/Unit/Language/DictionaryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testDictionaryGetter()
5252
}
5353

5454
$file = $this->getMockForAbstractClass(\Magento\Framework\Filesystem\File\ReadInterface::class);
55-
for ($i = 0; $i < count($data); $i++) {
55+
for ($i = 0, $count = count($data); $i < $count; $i++) {
5656
$file->expects($this->at($i))->method('readCsv')->will($this->returnValue($data[$i]));
5757
}
5858
$file->expects($this->at($i))->method('readCsv')->will($this->returnValue(false));

lib/internal/Magento/Framework/Archive.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ public function pack($source, $destination = 'packed.tgz', $skipRoot = false)
9696
{
9797
$archivers = $this->_getArchivers($destination);
9898
$interimSource = '';
99-
for ($i = 0; $i < count($archivers); $i++) {
100-
if ($i == count($archivers) - 1) {
99+
for ($i = 0, $count = count($archivers); $i < $count; $i++) {
100+
if ($i == $count - 1) {
101101
$packed = $destination;
102102
} else {
103103
$packed = dirname($destination) . '/~tmp-' . microtime(true) . $archivers[$i] . '.' . $archivers[$i];
104104
}
105105
$source = $this->_getArchiver($archivers[$i])->pack($source, $packed, $skipRoot);
106-
if ($interimSource && $i < count($archivers)) {
106+
if ($interimSource && $i < $count) {
107107
unlink($interimSource);
108108
}
109109
$interimSource = $source;

lib/internal/Magento/Framework/Cache/Backend/Memcached.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function save($data, $id, $tags = [], $specificLifetime = false)
8484
if (is_string($data) && strlen($data) > $this->_options['slab_size']) {
8585
$dataChunks = str_split($data, $this->_options['slab_size']);
8686

87-
for ($i = 0, $cnt = count($dataChunks); $i < $cnt; $i++) {
87+
for ($i = 0, $count = count($dataChunks); $i < $count; $i++) {
8888
$chunkId = $this->_getChunkId($id, $i);
8989

9090
if (!parent::save($dataChunks[$i], $chunkId, $tags, $specificLifetime)) {

0 commit comments

Comments
 (0)