Skip to content

Commit cabdc8b

Browse files
Sven Reichelkiatng
Sven Reichel
andauthored
Phpstan fixes (#4116)
* Rector: CQ - UnusedForeachValueToArrayKeysRector (#1) * Rector: CQ - UnusedForeachValueToArrayKeysRector See Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector * fixes + phpstan See fix at rector: rectorphp/rector-src#6164 * Fixed some phpstan issues * Revert "Rector: CQ - UnusedForeachValueToArrayKeysRector" This reverts commit 03e1514. * Revert ... * phpstan.dist.baseline.neon --------- Co-authored-by: Ng Kiat Siong <[email protected]>
1 parent 1d43dbb commit cabdc8b

File tree

14 files changed

+57
-231
lines changed

14 files changed

+57
-231
lines changed

app/code/core/Mage/ImportExport/Block/Adminhtml/Export/Filter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,11 @@ public function getFilterElementName($attributeCode)
434434
* Get row edit URL.
435435
*
436436
* @param Mage_Catalog_Model_Resource_Eav_Attribute $row
437-
* @return false
437+
* @return string
438438
*/
439439
public function getRowUrl($row)
440440
{
441-
return false;
441+
return '';
442442
}
443443

444444
/**

app/code/core/Mage/ImportExport/Helper/Data.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class Mage_ImportExport_Helper_Data extends Mage_Core_Helper_Data
3737
*/
3838
public function getMaxUploadSize()
3939
{
40-
return min(ini_get('post_max_size'), ini_get('upload_max_filesize'));
40+
$postMaxSizeBytes = ini_parse_quantity(ini_get('post_max_size'));
41+
$uploadMaxSizeBytes = ini_parse_quantity(ini_get('upload_max_filesize'));
42+
return min($postMaxSizeBytes, $uploadMaxSizeBytes);
4143
}
4244

4345
/**

app/code/core/Mage/ImportExport/Model/Export.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ protected function _getEntityAdapter()
6565

6666
if (isset($validTypes[$this->getEntity()])) {
6767
try {
68-
$this->_entityAdapter = Mage::getModel($validTypes[$this->getEntity()]['model']);
68+
/** @var Mage_ImportExport_Model_Export_Entity_Abstract $_entityAdapter */
69+
$_entityAdapter = Mage::getModel($validTypes[$this->getEntity()]['model']);
70+
$this->_entityAdapter = $_entityAdapter;
6971
} catch (Exception $e) {
7072
Mage::logException($e);
7173
Mage::throwException(
@@ -104,7 +106,9 @@ protected function _getWriter()
104106

105107
if (isset($validWriters[$this->getFileFormat()])) {
106108
try {
107-
$this->_writer = Mage::getModel($validWriters[$this->getFileFormat()]['model']);
109+
/** @var Mage_ImportExport_Model_Export_Adapter_Abstract $_writer */
110+
$_writer = Mage::getModel($validWriters[$this->getFileFormat()]['model']);
111+
$this->_writer = $_writer;
108112
} catch (Exception $e) {
109113
Mage::logException($e);
110114
Mage::throwException(
@@ -185,8 +189,7 @@ public function exportFile()
185189
Mage::throwException(
186190
Mage::helper('importexport')->__('There is no data for export')
187191
);
188-
}
189-
if ($result['rows']) {
192+
} else {
190193
$this->addLogComment([
191194
Mage::helper('importexport')->__('Exported %s rows.', $result['rows']),
192195
Mage::helper('importexport')->__('Export has been done.')

app/code/core/Mage/ImportExport/Model/Export/Entity/Abstract.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ abstract class Mage_ImportExport_Model_Export_Entity_Abstract
5252
/**
5353
* Entity type id.
5454
*
55-
* @var int
55+
* @var string|null
5656
*/
5757
protected $_entityTypeId;
5858

@@ -170,7 +170,10 @@ public function __construct()
170170
{
171171
$entityCode = $this->getEntityTypeCode();
172172
$this->_entityTypeId = Mage::getSingleton('eav/config')->getEntityType($entityCode)->getEntityTypeId();
173-
$this->_connection = Mage::getSingleton('core/resource')->getConnection('write');
173+
174+
/** @var Varien_Db_Adapter_Pdo_Mysql $_connection */
175+
$_connection = Mage::getSingleton('core/resource')->getConnection('write');
176+
$this->_connection = $_connection;
174177
}
175178

176179
/**
@@ -436,7 +439,7 @@ abstract public function getEntityTypeCode();
436439
/**
437440
* Entity type ID getter.
438441
*
439-
* @return int
442+
* @return string|null
440443
*/
441444
public function getEntityTypeId()
442445
{

app/code/core/Mage/ImportExport/Model/Import.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Mage_ImportExport_Model_Import extends Mage_ImportExport_Model_Abstract
5656
/**
5757
* Entity invalidated indexes.
5858
*
59-
* @var Mage_ImportExport_Model_Import_Entity_Abstract
59+
* @var array<string, array<int, string>>
6060
*/
6161
protected static $_entityInvalidatedIndexes = [
6262
'catalog_product' => [
@@ -80,7 +80,9 @@ protected function _getEntityAdapter()
8080

8181
if (isset($validTypes[$this->getEntity()])) {
8282
try {
83-
$this->_entityAdapter = Mage::getModel($validTypes[$this->getEntity()]['model']);
83+
/** @var Mage_ImportExport_Model_Import_Entity_Abstract $_entityAdapter */
84+
$_entityAdapter = Mage::getModel($validTypes[$this->getEntity()]['model']);
85+
$this->_entityAdapter = $_entityAdapter;
8486
} catch (Exception $e) {
8587
Mage::logException($e);
8688
Mage::throwException(
@@ -366,7 +368,7 @@ public function expandSource()
366368
if (!empty($row[$colName])) {
367369
preg_match($regExps[$regExpType], $row[$colName], $m);
368370

369-
$row[$colName] = $m[1] . ($m[2] + $size) . ($regExpType == 'middle' ? $m[3] : '');
371+
$row[$colName] = $m[1] . ((int) $m[2] + $size) . ($regExpType == 'middle' ? $m[3] : '');
370372
}
371373
}
372374
$writer->writeRow($row);

app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class Mage_ImportExport_Model_Import_Entity_Abstract
3333
/**
3434
* DB connection.
3535
*
36-
* @var Varien_Convert_Adapter_Interface
36+
* @var Varien_Db_Adapter_Pdo_Mysql
3737
*/
3838
protected $_connection;
3939

@@ -54,7 +54,7 @@ abstract class Mage_ImportExport_Model_Import_Entity_Abstract
5454
/**
5555
* Entity type id.
5656
*
57-
* @var int
57+
* @var string|null
5858
*/
5959
protected $_entityTypeId;
6060

@@ -183,10 +183,13 @@ abstract class Mage_ImportExport_Model_Import_Entity_Abstract
183183

184184
public function __construct()
185185
{
186-
$entityType = Mage::getSingleton('eav/config')->getEntityType($this->getEntityTypeCode());
186+
$entityType = Mage::getSingleton('eav/config')->getEntityType($this->getEntityTypeCode());
187187
$this->_entityTypeId = $entityType->getEntityTypeId();
188188
$this->_dataSourceModel = Mage_ImportExport_Model_Import::getDataSourceModel();
189-
$this->_connection = Mage::getSingleton('core/resource')->getConnection('write');
189+
190+
/** @var Varien_Db_Adapter_Pdo_Mysql $_connection */
191+
$_connection = Mage::getSingleton('core/resource')->getConnection('write');
192+
$this->_connection = $_connection;
190193
}
191194

192195
/**
@@ -398,7 +401,7 @@ abstract public function getEntityTypeCode();
398401
/**
399402
* Entity type ID getter.
400403
*
401-
* @return int
404+
* @return string|null
402405
*/
403406
public function getEntityTypeId()
404407
{

app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php

+1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ protected function _saveCustomers()
369369
$entityRowsIn = [];
370370
$entityRowsUp = [];
371371
$attributes = [];
372+
$entityId = null;
372373

373374
$oldCustomersToLower = array_change_key_case($this->_oldCustomers, CASE_LOWER);
374375

app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ class Mage_ImportExport_Model_Import_Entity_Product extends Mage_ImportExport_Mo
416416
/**
417417
* url_key attribute id
418418
*
419-
* @var int
419+
* @var string|false|null
420420
*/
421421
protected $_urlKeyAttributeId;
422422

@@ -901,6 +901,8 @@ protected function _saveCustomOptions()
901901
'updated_at' => Varien_Date::now()
902902
];
903903
}
904+
905+
$prevOptionId = 0;
904906
if ($rowIsMain) {
905907
$solidParams = [
906908
'option_id' => $nextOptionId,
@@ -1152,6 +1154,7 @@ protected function _saveLinks()
11521154
$productIds = [];
11531155
$linkRows = [];
11541156
$positionRows = [];
1157+
$sku = null;
11551158

11561159
foreach ($bunch as $rowNum => $rowData) {
11571160
$this->_filterRowData($rowData);
@@ -1362,6 +1365,7 @@ protected function _saveProducts()
13621365
$tierPrices = [];
13631366
$groupPrices = [];
13641367
$mediaGallery = [];
1368+
$rowSku = null;
13651369
$uploadedGalleryFiles = [];
13661370
$previousType = null;
13671371
$previousAttributeSet = null;
@@ -2207,7 +2211,7 @@ public function getAffectedEntityIds()
22072211
/**
22082212
* Get product url_key attribute id
22092213
*
2210-
* @return null|int
2214+
* @return string|false|null
22112215
*/
22122216
protected function _getUrlKeyAttributeId()
22132217
{

app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Configurable.php

+2
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ public function saveData()
356356
$newSku = $this->_entityModel->getNewSku();
357357
$oldSku = $this->_entityModel->getOldSku();
358358
$productSuperData = [];
359+
$productSuperAttrId = null;
360+
$productId = null;
359361
$productData = null;
360362
/** @var Mage_ImportExport_Model_Resource_Helper_Mysql4 $helper */
361363
$helper = Mage::getResourceHelper('importexport');

app/code/core/Mage/ImportExport/Model/Import/Entity/Product/Type/Grouped.php

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function saveData()
6565
$newSku = $this->_entityModel->getNewSku();
6666
$oldSku = $this->_entityModel->getOldSku();
6767
$attributes = [];
68+
$productData = [];
6869

6970
// pre-load attributes parameters
7071
$select = $connection->select()
@@ -101,6 +102,7 @@ public function saveData()
101102
} else {
102103
continue;
103104
}
105+
104106
$scope = $this->_entityModel->getRowScope($rowData);
105107
if (Mage_ImportExport_Model_Import_Entity_Product::SCOPE_DEFAULT == $scope) {
106108
$productData = $newSku[$rowData[Mage_ImportExport_Model_Import_Entity_Product::COL_SKU]];

app/code/core/Mage/Shipping/Model/Carrier/Abstract.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ abstract class Mage_Shipping_Model_Carrier_Abstract extends Varien_Object
9797
/**
9898
* Rate result data
9999
*
100-
* @var Mage_Shipping_Model_Rate_Result|null
100+
* @var Mage_Shipping_Model_Rate_Result|Mage_Shipping_Model_Tracking_Result|null
101101
*/
102102
protected $_result;
103103

app/code/core/Mage/Uploader/Helper/File.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ public function getUploadMaxSize()
703703
/**
704704
* Get max upload size
705705
*
706-
* @return mixed
706+
* @return string
707707
*/
708708
public function getDataMaxSize()
709709
{

app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,18 @@ class Mage_Usa_Model_Shipping_Carrier_Usps extends Mage_Usa_Model_Shipping_Carri
8585
*/
8686
protected $_rawRequest = null;
8787

88+
89+
/**
90+
* Raw rate tracking request data
91+
*
92+
* @var Varien_Object|null
93+
*/
94+
protected $_rawTrackRequest = null;
95+
8896
/**
8997
* Rate result data
9098
*
91-
* @var Mage_Shipping_Model_Rate_Result|null
99+
* @var Mage_Shipping_Model_Rate_Result|Mage_Shipping_Model_Tracking_Result|null
92100
*/
93101
protected $_result = null;
94102

@@ -425,7 +433,7 @@ protected function _getXmlQuotes()
425433
*
426434
* @link http://www.usps.com/webtools/htm/Rate-Calculators-v2-3.htm
427435
* @param string $response
428-
* @return Mage_Shipping_Model_Rate_Result
436+
* @return Mage_Shipping_Model_Rate_Result|void
429437
*/
430438
protected function _parseXmlResponse($response)
431439
{
@@ -512,6 +520,7 @@ protected function _parseXmlResponse($response)
512520
}
513521
}
514522
}
523+
515524
/**
516525
* Get configuration data of carrier
517526
*
@@ -901,7 +910,7 @@ public function getTracking($trackingData)
901910
/**
902911
* Set tracking request
903912
*
904-
* @return null
913+
* @return void
905914
*/
906915
protected function setTrackingRequest()
907916
{
@@ -960,7 +969,7 @@ protected function _getXmlTracking($trackingData)
960969
*
961970
* @param array $trackingValue
962971
* @param string $response
963-
* @return null
972+
* @return void
964973
*/
965974
protected function _parseXmlTrackingResponse($trackingValue, $response)
966975
{

0 commit comments

Comments
 (0)