Skip to content

Commit 689f46e

Browse files
authored
PhpStan: fix wrong params for str methods (#5071)
* PhpStan: fix wrong params for strlen * typo
1 parent a657351 commit 689f46e

File tree

4 files changed

+44
-68
lines changed

4 files changed

+44
-68
lines changed

.phpstan.dist.baseline.neon

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,12 +1326,6 @@ parameters:
13261326
count: 1
13271327
path: app/code/core/Mage/Catalog/Helper/Product/Compare.php
13281328

1329-
-
1330-
rawMessage: 'Parameter #3 $subject of function str_replace expects array<string>|string, float given.'
1331-
identifier: argument.type
1332-
count: 1
1333-
path: app/code/core/Mage/Catalog/Helper/Product/Type/Composite.php
1334-
13351329
-
13361330
rawMessage: 'Call to an undefined method Mage_Core_Model_Resource_Db_Collection_Abstract::setStoreId().'
13371331
identifier: method.notFound
@@ -3096,24 +3090,6 @@ parameters:
30963090
count: 1
30973091
path: app/code/core/Mage/Directory/Model/Currency/Import/Webservicex.php
30983092

3099-
-
3100-
rawMessage: 'Cannot call method streamRead() on resource.'
3101-
identifier: method.nonObject
3102-
count: 1
3103-
path: app/code/core/Mage/Downloadable/Helper/Download.php
3104-
3105-
-
3106-
rawMessage: 'Cannot call method streamStat() on resource.'
3107-
identifier: method.nonObject
3108-
count: 1
3109-
path: app/code/core/Mage/Downloadable/Helper/Download.php
3110-
3111-
-
3112-
rawMessage: 'Parameter #1 $string of function strtolower expects string, bool given.'
3113-
identifier: argument.type
3114-
count: 2
3115-
path: app/code/core/Mage/Downloadable/Helper/Download.php
3116-
31173093
-
31183094
rawMessage: 'Parameter #2 $code of class Exception constructor expects int, string given.'
31193095
identifier: argument.type
@@ -6018,18 +5994,6 @@ parameters:
60185994
count: 1
60195995
path: lib/Varien/Data/Form/Element/Multiline.php
60205996

6021-
-
6022-
rawMessage: 'Parameter #1 $string of function str_pad expects string, int<0, 23> given.'
6023-
identifier: argument.type
6024-
count: 1
6025-
path: lib/Varien/Data/Form/Element/Time.php
6026-
6027-
-
6028-
rawMessage: 'Parameter #1 $string of function str_pad expects string, int<0, 59> given.'
6029-
identifier: argument.type
6030-
count: 2
6031-
path: lib/Varien/Data/Form/Element/Time.php
6032-
60335997
-
60345998
rawMessage: 'Method Varien_Data_Tree::load() invoked with 2 parameters, 0-1 required.'
60355999
identifier: arguments.count

app/code/core/Mage/Catalog/Helper/Product/Type/Composite.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class Mage_Catalog_Helper_Product_Type_Composite extends Mage_Core_Helper_Abstra
2323
* @param float $price
2424
* @param bool $isPercent
2525
* @param null|int $storeId
26-
* @return mixed
26+
* @throws Mage_Core_Model_Store_Exception
27+
* @return string
2728
*/
2829
public function preparePrice($product, $price, $isPercent = false, $storeId = null)
2930
{
@@ -41,7 +42,8 @@ public function preparePrice($product, $price, $isPercent = false, $storeId = nu
4142
* @param float $price
4243
* @param bool $isPercent
4344
* @param null|int $storeId
44-
* @return mixed
45+
* @throws Mage_Core_Model_Store_Exception
46+
* @return string
4547
*/
4648
public function prepareOldPrice($product, $price, $isPercent = false, $storeId = null)
4749
{
@@ -60,7 +62,7 @@ public function prepareOldPrice($product, $price, $isPercent = false, $storeId =
6062
*/
6163
public function registerJsPrice($price)
6264
{
63-
return str_replace(',', '.', $price);
65+
return str_replace(',', '.', (string) $price);
6466
}
6567

6668
/**
@@ -69,6 +71,7 @@ public function registerJsPrice($price)
6971
* @param float $price
7072
* @param bool $round
7173
* @param null|int $storeId
74+
* @throws Mage_Core_Model_Store_Exception
7275
* @return float|int
7376
*/
7477
public function convertPrice($price, $round = false, $storeId = null)
@@ -122,11 +125,12 @@ public function prepareJsonGeneralConfig()
122125

123126
/**
124127
* Prepare product specific params to be used in getJsonConfig()
125-
* @see Mage_Catalog_Block_Product_View::getJsonConfig()
126-
* @see Mage_ConfigurableSwatches_Block_Catalog_Product_List_Price::getJsonConfig()
127-
*
128128
* @param Mage_Catalog_Model_Product $product
129+
* @throws Mage_Core_Model_Store_Exception
129130
* @return array
131+
*
132+
* @see Mage_ConfigurableSwatches_Block_Catalog_Product_List_Price::getJsonConfig()
133+
* @see Mage_Catalog_Block_Product_View::getJsonConfig()
130134
*/
131135
public function prepareJsonProductConfig($product)
132136
{

app/code/core/Mage/Downloadable/Helper/Download.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ class Mage_Downloadable_Helper_Download extends Mage_Core_Helper_Abstract
6767
/**
6868
* Retrieve Resource file handle (socket, file pointer etc)
6969
*
70-
* @return resource
70+
* @throws Mage_Core_Exception
71+
* @throws Exception
72+
* @return resource|Varien_Io_File
7173
*/
7274
protected function _getHandle()
7375
{
@@ -82,7 +84,7 @@ protected function _getHandle()
8284
*/
8385
$urlProp = parse_url($this->_resourceFile);
8486
if (!isset($urlProp['scheme'])
85-
|| strtolower($urlProp['scheme'] != 'http') && strtolower($urlProp['scheme'] != 'https')
87+
|| strtolower($urlProp['scheme']) != 'http' && strtolower($urlProp['scheme']) != 'https'
8688
) {
8789
Mage::throwException(Mage::helper('downloadable')->__('Invalid download URL scheme.'));
8890
}
@@ -116,8 +118,8 @@ protected function _getHandle()
116118

117119
try {
118120
$this->_handle = fsockopen($hostname, $port, $errno, $errstr);
119-
} catch (Exception $e) {
120-
throw $e;
121+
} catch (Exception $exception) {
122+
throw $exception;
121123
}
122124

123125
if ($this->_handle === false) {
@@ -139,11 +141,11 @@ protected function _getHandle()
139141

140142
$match = [];
141143
if (preg_match('#^([^:]+): (.*)\s+$#', $str, $match)) {
142-
$k = strtolower($match[1]);
143-
if ($k == 'set-cookie') {
144+
$key = strtolower($match[1]);
145+
if ($key == 'set-cookie') {
144146
continue;
145147
} else {
146-
$this->_urlHeaders[$k] = trim($match[2]);
148+
$this->_urlHeaders[$key] = trim($match[2]);
147149
}
148150
} elseif (preg_match('#^HTTP/[0-9\.]+ (\d+) (.*)\s$#', $str, $match)) {
149151
$this->_urlHeaders['code'] = $match[1];
@@ -176,6 +178,8 @@ protected function _getHandle()
176178

177179
/**
178180
* Retrieve file size in bytes
181+
*
182+
* @throws Mage_Core_Exception
179183
*/
180184
public function getFilesize()
181185
{
@@ -197,7 +201,7 @@ public function getFilesize()
197201
*/
198202
public function getContentType()
199203
{
200-
$handle = $this->_getHandle();
204+
$this->_getHandle();
201205
if ($this->_linkType == self::LINK_TYPE_FILE) {
202206
if (function_exists('mime_content_type') && ($contentType = mime_content_type($this->_resourceFile))) {
203207
return $contentType;
@@ -215,13 +219,13 @@ public function getContentType()
215219
}
216220

217221
/**
218-
* @throws Exception
219-
* @return bool|mixed|string
220222
* @SuppressWarnings("PHPMD.ErrorControlOperator")
223+
* @throws Exception
224+
* @return array|string
221225
*/
222226
public function getFilename()
223227
{
224-
$handle = $this->_getHandle();
228+
$this->_getHandle();
225229
if ($this->_linkType == self::LINK_TYPE_FILE) {
226230
return pathinfo($this->_resourceFile, PATHINFO_BASENAME);
227231
} elseif ($this->_linkType == self::LINK_TYPE_URL) {
@@ -245,6 +249,7 @@ public function getFilename()
245249
*
246250
* @param string $resourceFile
247251
* @param string $linkType
252+
* @throws Mage_Core_Exception
248253
* @return $this
249254
*/
250255
public function setResource($resourceFile, $linkType = self::LINK_TYPE_FILE)
@@ -282,6 +287,9 @@ public function getHttpResponse()
282287
return Mage::app()->getFrontController()->getResponse();
283288
}
284289

290+
/**
291+
* @throws Mage_Core_Exception
292+
*/
285293
public function output()
286294
{
287295
$handle = $this->_getHandle();

lib/Varien/Data/Form/Element/Time.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,40 +44,40 @@ public function getElementHtml()
4444
{
4545
$this->addClass('select');
4646

47-
$value_hrs = 0;
48-
$value_min = 0;
49-
$value_sec = 0;
47+
$valueHrs = 0;
48+
$valueMin = 0;
49+
$valueSec = 0;
5050

5151
if ($value = $this->getValue()) {
5252
$values = explode(',', $value);
5353
if (count($values) === 3) {
54-
$value_hrs = $values[0];
55-
$value_min = $values[1];
56-
$value_sec = $values[2];
54+
$valueHrs = $values[0];
55+
$valueMin = $values[1];
56+
$valueSec = $values[2];
5757
}
5858
}
5959

6060
$html = '<input type="hidden" id="' . $this->getHtmlId() . '" />';
6161
$html .= '<select name="' . $this->getName() . '" ' . $this->serialize($this->getHtmlAttributes()) . ' style="width:40px">' . "\n";
62-
for ($i = 0; $i < 24; $i++) {
63-
$hour = str_pad($i, 2, '0', STR_PAD_LEFT);
64-
$html .= '<option value="' . $hour . '" ' . (($value_hrs == $i) ? 'selected="selected"' : '') . '>' . $hour . '</option>';
62+
for ($index = 0; $index < 24; $index++) {
63+
$hour = str_pad((string) $index, 2, '0', STR_PAD_LEFT);
64+
$html .= '<option value="' . $hour . '" ' . (($valueHrs == $index) ? 'selected="selected"' : '') . '>' . $hour . '</option>';
6565
}
6666

6767
$html .= '</select>' . "\n";
6868

6969
$html .= '&nbsp;:&nbsp;<select name="' . $this->getName() . '" ' . $this->serialize($this->getHtmlAttributes()) . ' style="width:40px">' . "\n";
70-
for ($i = 0; $i < 60; $i++) {
71-
$hour = str_pad($i, 2, '0', STR_PAD_LEFT);
72-
$html .= '<option value="' . $hour . '" ' . (($value_min == $i) ? 'selected="selected"' : '') . '>' . $hour . '</option>';
70+
for ($index = 0; $index < 60; $index++) {
71+
$hour = str_pad((string) $index, 2, '0', STR_PAD_LEFT);
72+
$html .= '<option value="' . $hour . '" ' . (($valueMin == $index) ? 'selected="selected"' : '') . '>' . $hour . '</option>';
7373
}
7474

7575
$html .= '</select>' . "\n";
7676

7777
$html .= '&nbsp;:&nbsp;<select name="' . $this->getName() . '" ' . $this->serialize($this->getHtmlAttributes()) . ' style="width:40px">' . "\n";
78-
for ($i = 0; $i < 60; $i++) {
79-
$hour = str_pad($i, 2, '0', STR_PAD_LEFT);
80-
$html .= '<option value="' . $hour . '" ' . (($value_sec == $i) ? 'selected="selected"' : '') . '>' . $hour . '</option>';
78+
for ($index = 0; $index < 60; $index++) {
79+
$hour = str_pad((string) $index, 2, '0', STR_PAD_LEFT);
80+
$html .= '<option value="' . $hour . '" ' . (($valueSec == $index) ? 'selected="selected"' : '') . '>' . $hour . '</option>';
8181
}
8282

8383
$html .= '</select>' . "\n";

0 commit comments

Comments
 (0)