Skip to content

Commit a657351

Browse files
authored
PhpStan: fix wrong params for strlen (#5070)
* phpstan: fix `strlen` parameters * typo * typo * typo
1 parent fb5f95d commit a657351

File tree

7 files changed

+119
-140
lines changed

7 files changed

+119
-140
lines changed

.phpstan.dist.baseline.neon

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -744,12 +744,6 @@ parameters:
744744
count: 1
745745
path: app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php
746746

747-
-
748-
rawMessage: 'Parameter #1 $modelClass of static method Mage::getModel() expects string, array given.'
749-
identifier: argument.type
750-
count: 1
751-
path: app/code/core/Mage/Adminhtml/controllers/System/CurrencyController.php
752-
753747
-
754748
rawMessage: 'Method Mage_Directory_Model_Country::loadByCode() invoked with 2 parameters, 1 required.'
755749
identifier: arguments.count
@@ -840,36 +834,12 @@ parameters:
840834
count: 1
841835
path: app/code/core/Mage/Api/Model/Server/V2/Adapter/Soap.php
842836

843-
-
844-
rawMessage: 'Parameter #1 $string of function strlen expects string, array given.'
845-
identifier: argument.type
846-
count: 1
847-
path: app/code/core/Mage/Api/Model/Server/V2/Handler.php
848-
849-
-
850-
rawMessage: 'Parameter #2 $needle of function str_contains expects string, array given.'
851-
identifier: argument.type
852-
count: 1
853-
path: app/code/core/Mage/Api/Model/Server/V2/Handler.php
854-
855837
-
856838
rawMessage: 'Return type (Mage_Api_Model_Wsdl_Config) of method Mage_Api_Model_Server_Wsi_Adapter_Soap::_getWsdlConfig() should be compatible with return type (Varien_Object) of method Mage_Api_Model_Server_Adapter_Soap::_getWsdlConfig()'
857839
identifier: method.childReturnType
858840
count: 1
859841
path: app/code/core/Mage/Api/Model/Server/Wsi/Adapter/Soap.php
860842

861-
-
862-
rawMessage: 'Parameter #1 $string of function strlen expects string, array given.'
863-
identifier: argument.type
864-
count: 1
865-
path: app/code/core/Mage/Api/Model/Server/Wsi/Handler.php
866-
867-
-
868-
rawMessage: 'Parameter #2 $needle of function str_contains expects string, array given.'
869-
identifier: argument.type
870-
count: 1
871-
path: app/code/core/Mage/Api/Model/Server/Wsi/Handler.php
872-
873843
-
874844
rawMessage: 'Return type (stdClass) of method Mage_Api_Model_Server_Wsi_Handler::endSession() should be compatible with return type (true) of method Mage_Api_Model_Server_Handler_Abstract::endSession()'
875845
identifier: method.childReturnType
@@ -888,12 +858,6 @@ parameters:
888858
count: 1
889859
path: app/code/core/Mage/Api/Model/Session.php
890860

891-
-
892-
rawMessage: Invalid array key type array.
893-
identifier: offsetAccess.invalidOffset
894-
count: 1
895-
path: app/code/core/Mage/Api/Model/Wsdl/Config.php
896-
897861
-
898862
rawMessage: 'Call to an undefined method SimpleXMLElement::extendChild().'
899863
identifier: method.notFound
@@ -1536,12 +1500,6 @@ parameters:
15361500
count: 1
15371501
path: app/code/core/Mage/Catalog/Model/Layer/Filter/Decimal.php
15381502

1539-
-
1540-
rawMessage: 'Parameter #1 $string of function strlen expects string, float given.'
1541-
identifier: argument.type
1542-
count: 1
1543-
path: app/code/core/Mage/Catalog/Model/Layer/Filter/Decimal.php
1544-
15451503
-
15461504
rawMessage: 'Parameter #2 $range of method Mage_Catalog_Model_Resource_Layer_Filter_Decimal::applyFilterToCollection() expects float, string given.'
15471505
identifier: argument.type
@@ -1560,12 +1518,6 @@ parameters:
15601518
count: 1
15611519
path: app/code/core/Mage/Catalog/Model/Layer/Filter/Decimal.php
15621520

1563-
-
1564-
rawMessage: 'Parameter #1 $string of function strlen expects string, float given.'
1565-
identifier: argument.type
1566-
count: 1
1567-
path: app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php
1568-
15691521
-
15701522
rawMessage: 'Method Mage_Catalog_Model_Resource_Category_Flat::move() invoked with 3 parameters, 1 required.'
15711523
identifier: arguments.count
@@ -3144,12 +3096,6 @@ parameters:
31443096
count: 1
31453097
path: app/code/core/Mage/Directory/Model/Currency/Import/Webservicex.php
31463098

3147-
-
3148-
rawMessage: 'Parameter #1 $modelClass of static method Mage::getModel() expects string, array given.'
3149-
identifier: argument.type
3150-
count: 1
3151-
path: app/code/core/Mage/Directory/Model/Observer.php
3152-
31533099
-
31543100
rawMessage: 'Cannot call method streamRead() on resource.'
31553101
identifier: method.nonObject
@@ -4938,12 +4884,6 @@ parameters:
49384884
count: 3
49394885
path: app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Label/Pdf/PageBuilder.php
49404886

4941-
-
4942-
rawMessage: 'Parameter #1 $string of function strlen expects string, bool given.'
4943-
identifier: argument.type
4944-
count: 1
4945-
path: app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Label/Pdf/PageBuilder.php
4946-
49474887
-
49484888
rawMessage: Access to an undefined property Mage_Usa_Model_Shipping_Carrier_Fedex::$_defaultGatewayUrl.
49494889
identifier: property.notFound

app/code/core/Mage/Api/Model/Server/Wsi/Handler.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class Mage_Api_Model_Server_Wsi_Handler extends Mage_Api_Model_Server_Handler_Ab
2121
*
2222
* @param string $function
2323
* @param array $args
24+
* @throws Mage_Api_Exception
25+
* @throws ReflectionException
2426
* @return stdClass
2527
*/
2628
public function __call($function, $args)
@@ -122,6 +124,7 @@ protected function _getResourceName($apiPath)
122124
*
123125
* @param String $modelName
124126
* @param String $methodName
127+
* @throws ReflectionException
125128
* @return array of ReflectionParameter
126129
*/
127130
public function getMethodParams($modelName, $methodName)
@@ -136,6 +139,7 @@ public function getMethodParams($modelName, $methodName)
136139
*
137140
* @param array $params
138141
* @param array $args
142+
* @throws ReflectionException
139143
* @return array
140144
*/
141145
public function prepareArgs($params, $args)

app/code/core/Mage/Catalog/Model/Layer/Filter/Decimal.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ protected function _getResource()
5252
* Apply decimal range filter to product collection
5353
*
5454
* @param Mage_Catalog_Block_Layer_Filter_Decimal $filterBlock
55+
* @throws Mage_Core_Model_Store_Exception
5556
* @return $this
5657
*/
5758
public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
@@ -102,6 +103,7 @@ protected function _getCacheKey()
102103
*
103104
* @param int $range
104105
* @param float $value
106+
* @throws Mage_Core_Model_Store_Exception
105107
* @return string
106108
*/
107109
protected function _renderItemLabel($range, $value)
@@ -157,7 +159,7 @@ public function getRange()
157159
$maxValue = $this->getMaxValue();
158160
$index = 1;
159161
do {
160-
$range = 10 ** (strlen(floor($maxValue)) - $index);
162+
$range = 10 ** (strlen((string) floor($maxValue)) - $index);
161163
$items = $this->getRangeItemCounts($range);
162164
$index++;
163165
} while ($range > self::MIN_RANGE_POWER && count($items) < 2);
@@ -189,6 +191,7 @@ public function getRangeItemCounts($range)
189191
/**
190192
* Retrieve data for build decimal filter items
191193
*
194+
* @throws Mage_Core_Model_Store_Exception
192195
* @return array
193196
*/
194197
protected function _getItemsData()

app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ protected function _getResource()
8181
/**
8282
* Get price range for building filter steps
8383
*
84+
* @throws Mage_Core_Model_Store_Exception
8485
* @return int
8586
*/
8687
public function getPriceRange()
@@ -100,7 +101,7 @@ public function getPriceRange()
100101
if ($calculation == self::RANGE_CALCULATION_AUTO) {
101102
$index = 1;
102103
do {
103-
$range = 10 ** (strlen(floor($maxPrice)) - $index);
104+
$range = 10 ** (strlen((string) floor($maxPrice)) - $index);
104105
$items = $this->getRangeItemCounts($range);
105106
$index++;
106107
} while ($range > self::MIN_RANGE_POWER && count($items) < 2);
@@ -136,6 +137,7 @@ public function getMaxPriceInt()
136137
* Get information about products count in range
137138
*
138139
* @param int $range
140+
* @throws Mage_Core_Model_Store_Exception
139141
* @return array
140142
*/
141143
public function getRangeItemCounts($range)
@@ -145,17 +147,17 @@ public function getRangeItemCounts($range)
145147
if (is_null($items)) {
146148
$items = $this->_getResource()->getCount($this, $range);
147149
// checking max number of intervals
148-
$i = 0;
150+
$index = 0;
149151
$lastIndex = null;
150152
$maxIntervalsNumber = $this->getMaxIntervalsNumber();
151153
$calculation = Mage::app()->getStore()->getConfig(self::XML_PATH_RANGE_CALCULATION);
152-
foreach ($items as $k => $v) {
153-
++$i;
154-
if ($calculation == self::RANGE_CALCULATION_MANUAL && $i > 1 && $i > $maxIntervalsNumber) {
155-
$items[$lastIndex] += $v;
156-
unset($items[$k]);
154+
foreach ($items as $key => $value) {
155+
++$index;
156+
if ($calculation == self::RANGE_CALCULATION_MANUAL && $index > 1 && $index > $maxIntervalsNumber) {
157+
$items[$lastIndex] += $value;
158+
unset($items[$key]);
157159
} else {
158-
$lastIndex = $k;
160+
$lastIndex = $key;
159161
}
160162
}
161163

@@ -168,10 +170,11 @@ public function getRangeItemCounts($range)
168170
/**
169171
* Prepare text of item label
170172
*
171-
* @deprecated since 1.7.0.0
172173
* @param int $range
173174
* @param float $value
175+
* @throws Mage_Core_Model_Store_Exception
174176
* @return string
177+
* @deprecated since 1.7.0.0
175178
*/
176179
protected function _renderItemLabel($range, $value)
177180
{
@@ -187,6 +190,7 @@ protected function _renderItemLabel($range, $value)
187190
*
188191
* @param float|string $fromPrice
189192
* @param float|string $toPrice
193+
* @throws Mage_Core_Model_Store_Exception
190194
* @return string
191195
*/
192196
protected function _renderRangeLabel($fromPrice, $toPrice)
@@ -208,8 +212,10 @@ protected function _renderRangeLabel($fromPrice, $toPrice)
208212

209213
/**
210214
* Get price aggreagation data cache key
211-
* @deprecated after 1.4
215+
*
216+
* @throws Mage_Core_Model_Store_Exception
212217
* @return string
218+
* @deprecated after 1.4
213219
*/
214220
protected function _getCacheKey()
215221
{
@@ -247,6 +253,7 @@ protected function _getAdditionalRequestData()
247253
/**
248254
* Get data generated by algorithm for build price filter items
249255
*
256+
* @throws Mage_Core_Model_Store_Exception
250257
* @return array
251258
*/
252259
protected function _getCalculatedItemsData()
@@ -292,6 +299,7 @@ protected function _getCalculatedItemsData()
292299
/**
293300
* Get data for build price filter items
294301
*
302+
* @throws Mage_Core_Model_Store_Exception
295303
* @return array
296304
*/
297305
protected function _getItemsData()
@@ -349,8 +357,8 @@ protected function _validateFilter($filter)
349357
return false;
350358
}
351359

352-
foreach ($filter as $v) {
353-
if (($v !== '' && $v !== '0' && (float) $v <= 0) || is_infinite((float) $v)) {
360+
foreach ($filter as $value) {
361+
if (($value !== '' && $value !== '0' && (float) $value <= 0) || is_infinite((float) $value)) {
354362
return false;
355363
}
356364
}
@@ -362,6 +370,7 @@ protected function _validateFilter($filter)
362370
* Apply price range filter
363371
*
364372
* @param Varien_Object $filterBlock deprecated
373+
* @throws Mage_Core_Model_Store_Exception
365374
* @return $this
366375
*/
367376
public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
@@ -387,8 +396,8 @@ public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
387396

388397
$priorFilters = [];
389398
$counter = count($filterParams);
390-
for ($i = 1; $i < $counter; ++$i) {
391-
$priorFilter = $this->_validateFilter($filterParams[$i]);
399+
for ($index = 1; $index < $counter; ++$index) {
400+
$priorFilter = $this->_validateFilter($filterParams[$index]);
392401
if ($priorFilter) {
393402
$priorFilters[] = $priorFilter;
394403
} else {
@@ -454,6 +463,7 @@ public function setCustomerGroupId($customerGroupId)
454463
/**
455464
* Retrieve active currency rate for filter
456465
*
466+
* @throws Mage_Core_Model_Store_Exception
457467
* @return float
458468
*/
459469
public function getCurrencyRate()
@@ -484,6 +494,7 @@ public function setCurrencyRate($rate)
484494
/**
485495
* Get maximum number of intervals
486496
*
497+
* @throws Mage_Core_Model_Store_Exception
487498
* @return int
488499
*/
489500
public function getMaxIntervalsNumber()
@@ -494,6 +505,7 @@ public function getMaxIntervalsNumber()
494505
/**
495506
* Get interval division limit
496507
*
508+
* @throws Mage_Core_Model_Store_Exception
497509
* @return int
498510
*/
499511
public function getIntervalDivisionLimit()
@@ -524,6 +536,7 @@ public function getResetValue()
524536
/**
525537
* Get 'clear price' link text
526538
*
539+
* @throws Mage_Core_Model_Store_Exception
527540
* @return false|string
528541
*/
529542
public function getClearLinkText()

app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public function deleteFile($target)
271271
*
272272
* @param string $targetPath Target directory
273273
* @param string $type Type of storage, e.g. image, media etc.
274-
*@throws Mage_Core_Exception
274+
* @throws Mage_Core_Exception
275275
* @return array|bool|void
276276
*/
277277
public function uploadFile($targetPath, $type = null)

0 commit comments

Comments
 (0)