Skip to content

Commit 60e77f0

Browse files
committed
Quality Assurance > The use of function sizeof() is discouraged; use count() instead
1 parent 68d2137 commit 60e77f0

File tree

35 files changed

+141
-89
lines changed

35 files changed

+141
-89
lines changed

app/code/Magento/Backend/Block/Widget/Grid.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,10 @@ protected function _addColumnFilterToCollection($column)
300300
if ($this->getCollection()) {
301301
$field = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex();
302302
if ($column->getFilterConditionCallback()) {
303-
call_user_func($column->getFilterConditionCallback(), $this->getCollection(), $column);
303+
$column->getFilterConditionCallback()[0]->{$column->getFilterConditionCallback()[1]}(
304+
$this->getCollection(),
305+
$column
306+
);
304307
} else {
305308
$condition = $column->getFilter()->getCondition();
306309
if ($field && isset($condition)) {
@@ -363,7 +366,7 @@ protected function _prepareCollection()
363366
$this->_setFilterValues($data);
364367
} elseif ($filter && is_array($filter)) {
365368
$this->_setFilterValues($filter);
366-
} elseif (0 !== sizeof($this->_defaultFilter)) {
369+
} elseif (0 !== count($this->_defaultFilter)) {
367370
$this->_setFilterValues($this->_defaultFilter);
368371
}
369372

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Action.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function render(\Magento\Framework\DataObject $row)
4747
return ' ';
4848
}
4949

50-
if (sizeof($actions) == 1 && !$this->getColumn()->getNoLink()) {
50+
if (count($actions) == 1 && !$this->getColumn()->getNoLink()) {
5151
foreach ($actions as $action) {
5252
if (is_array($action)) {
5353
return $this->_toLinkHtml($action, $row);
@@ -117,8 +117,8 @@ protected function _toLinkHtml($action, \Magento\Framework\DataObject $row)
117117
/**
118118
* Prepares action data for html render
119119
*
120-
* @param array &$action
121-
* @param string &$actionCaption
120+
* @param &array $action
121+
* @param &string $actionCaption
122122
* @param \Magento\Framework\DataObject $row
123123
* @return $this
124124
* @SuppressWarnings(PHPMD.CyclomaticComplexity)

app/code/Magento/Backend/Helper/Dashboard/AbstractDashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getItems()
5858
*/
5959
public function getCount()
6060
{
61-
return sizeof($this->getItems());
61+
return count($this->getItems());
6262
}
6363

6464
/**

app/code/Magento/Backend/Helper/Dashboard/Data.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function getStores()
6868
*/
6969
public function countStores()
7070
{
71-
return sizeof($this->_stores->getItems());
71+
return count($this->_stores->getItems());
7272
}
7373

7474
/**
@@ -88,15 +88,15 @@ public function getDatePeriods()
8888
}
8989

9090
/**
91-
* Create data hash to ensure that we got valid
92-
* data and it is not changed by some one else.
91+
* Create data hash to ensure that we got valid data and it is not changed by some one else.
9392
*
9493
* @param string $data
9594
* @return string
9695
*/
9796
public function getChartDataHash($data)
9897
{
9998
$secret = $this->_installDate;
99+
// phpcs:disable Magento2.Security.InsecureFunction.FoundWithAlternative
100100
return md5($data . $secret);
101101
}
102102
}

app/code/Magento/Catalog/Model/Entity/Product/Attribute/Design/Options/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Container extends \Magento\Eav\Model\Entity\Attribute\Source\Config
2121
public function getOptionText($value)
2222
{
2323
$options = $this->getAllOptions();
24-
if (sizeof($options) > 0) {
24+
if (count($options) > 0) {
2525
foreach ($options as $option) {
2626
if (isset($option['value']) && $option['value'] == $value) {
2727
return __($option['label']);

app/code/Magento/Catalog/Test/Unit/Model/Product/Type/PriceTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,13 @@ public function testTierPrices($priceScope, $expectedWebsiteId)
165165
$this->websiteMock->expects($this->any())->method('getId')->will($this->returnValue($expectedWebsiteId));
166166
$this->tpFactory->expects($this->any())
167167
->method('create')
168-
->will($this->returnCallback(function () {
169-
return $this->objectManagerHelper->getObject(\Magento\Catalog\Model\Product\TierPrice::class);
170-
}));
168+
->will(
169+
$this->returnCallback(
170+
function () {
171+
return $this->objectManagerHelper->getObject(\Magento\Catalog\Model\Product\TierPrice::class);
172+
}
173+
)
174+
);
171175

172176
// create sample TierPrice objects that would be coming from a REST call
173177
$tierPriceExtensionMock = $this->getMockBuilder(ProductTierPriceExtensionInterface::class)
@@ -198,9 +202,10 @@ public function testTierPrices($priceScope, $expectedWebsiteId)
198202
$tpArray = $this->product->getData($this::KEY_TIER_PRICE);
199203
$this->assertNotNull($tpArray);
200204
$this->assertTrue(is_array($tpArray));
201-
$this->assertEquals(sizeof($tps), sizeof($tpArray));
205+
$this->assertEquals(count($tps), count($tpArray));
202206

203-
for ($i = 0; $i < sizeof($tps); $i++) {
207+
$count = count($tps);
208+
for ($i = 0; $i < $count; $i++) {
204209
$tpData = $tpArray[$i];
205210
$this->assertEquals($expectedWebsiteId, $tpData['website_id'], 'Website Id does not match');
206211
$this->assertEquals($tps[$i]->getValue(), $tpData['price'], 'Price/Value does not match');
@@ -226,12 +231,13 @@ public function testTierPrices($priceScope, $expectedWebsiteId)
226231
$tpRests = $this->model->getTierPrices($this->product);
227232
$this->assertNotNull($tpRests);
228233
$this->assertTrue(is_array($tpRests));
229-
$this->assertEquals(sizeof($tps), sizeof($tpRests));
234+
$this->assertEquals(count($tps), count($tpRests));
230235
foreach ($tpRests as $tpRest) {
231236
$this->assertEquals(50, $tpRest->getExtensionAttributes()->getPercentageValue());
232237
}
233238

234-
for ($i = 0; $i < sizeof($tps); $i++) {
239+
$count = count($tps);
240+
for ($i = 0; $i < $count; $i++) {
235241
$this->assertEquals(
236242
$tps[$i]->getValue(),
237243
$tpRests[$i]->getValue(),

app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ protected function generalTestGetDirsCollection($path, $collectionArray = [], $e
454454
$storageCollectionMock->expects($this->once())
455455
->method('getIterator')
456456
->willReturn(new \ArrayIterator($collectionArray));
457-
$storageCollectionInvMock = $storageCollectionMock->expects($this->exactly(sizeof($expectedRemoveKeys)))
457+
$storageCollectionInvMock = $storageCollectionMock->expects($this->exactly(count($expectedRemoveKeys)))
458458
->method('removeItemByKey');
459459
call_user_func_array([$storageCollectionInvMock, 'withConsecutive'], $expectedRemoveKeys);
460460

app/code/Magento/Cron/Model/Schedule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function _construct()
9797
public function setCronExpr($expr)
9898
{
9999
$e = preg_split('#\s+#', $expr, null, PREG_SPLIT_NO_EMPTY);
100-
if (sizeof($e) < 5 || sizeof($e) > 6) {
100+
if (count($e) < 5 || count($e) > 6) {
101101
throw new CronException(__('Invalid cron expression: %1', $expr));
102102
}
103103

@@ -168,7 +168,7 @@ public function matchCronExpression($expr, $num)
168168
// handle modulus
169169
if (strpos($expr, '/') !== false) {
170170
$e = explode('/', $expr);
171-
if (sizeof($e) !== 2) {
171+
if (count($e) !== 2) {
172172
throw new CronException(__('Invalid cron expression, expecting \'match/modulus\': %1', $expr));
173173
}
174174
if (!is_numeric($e[1])) {
@@ -187,7 +187,7 @@ public function matchCronExpression($expr, $num)
187187
} elseif (strpos($expr, '-') !== false) {
188188
// handle range
189189
$e = explode('-', $expr);
190-
if (sizeof($e) !== 2) {
190+
if (count($e) !== 2) {
191191
throw new CronException(__('Invalid cron expression, expecting \'from-to\' structure: %1', $expr));
192192
}
193193

app/code/Magento/CurrencySymbol/Block/Adminhtml/System/Currency/Rate/Matrix.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
*/
1212
namespace Magento\CurrencySymbol\Block\Adminhtml\System\Currency\Rate;
1313

14+
/**
15+
* Manage currency block
16+
*/
1417
class Matrix extends \Magento\Backend\Block\Template
1518
{
1619
/**
@@ -105,7 +108,7 @@ protected function _prepareRates($array)
105108
foreach ($array as $key => $rate) {
106109
foreach ($rate as $code => $value) {
107110
$parts = explode('.', $value);
108-
if (sizeof($parts) == 2) {
111+
if (count($parts) == 2) {
109112
$parts[1] = str_pad(rtrim($parts[1], 0), 4, '0', STR_PAD_RIGHT);
110113
$array[$key][$code] = join('.', $parts);
111114
} elseif ($value > 0) {

app/code/Magento/Directory/Model/ResourceModel/Currency.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function getAnyRate($currencyFrom, $currencyTo)
138138
*/
139139
public function saveRates($rates)
140140
{
141-
if (is_array($rates) && sizeof($rates) > 0) {
141+
if (is_array($rates) && count($rates) > 0) {
142142
$connection = $this->getConnection();
143143
$data = [];
144144
foreach ($rates as $currencyCode => $rate) {
@@ -176,7 +176,7 @@ public function getConfigCurrencies($model, $path)
176176
$result = [];
177177
$rowSet = $connection->fetchAll($select, $bind);
178178
foreach ($rowSet as $row) {
179-
$result = array_merge($result, explode(',', $row['value']));
179+
$result[] = explode(',', $row['value']);
180180
}
181181
sort($result);
182182

0 commit comments

Comments
 (0)