Skip to content

Commit

Permalink
Phpstan fixes (#4116)
Browse files Browse the repository at this point in the history
* 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 <kiatsiong.ng@gmail.com>
  • Loading branch information
sreichel and kiatng authored Jul 29, 2024
1 parent 1d43dbb commit cabdc8b
Showing 14 changed files with 57 additions and 231 deletions.
Original file line number Diff line number Diff line change
@@ -434,11 +434,11 @@ public function getFilterElementName($attributeCode)
* Get row edit URL.
*
* @param Mage_Catalog_Model_Resource_Eav_Attribute $row
* @return false
* @return string
*/
public function getRowUrl($row)
{
return false;
return '';
}

/**
4 changes: 3 additions & 1 deletion app/code/core/Mage/ImportExport/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -37,7 +37,9 @@ class Mage_ImportExport_Helper_Data extends Mage_Core_Helper_Data
*/
public function getMaxUploadSize()
{
return min(ini_get('post_max_size'), ini_get('upload_max_filesize'));
$postMaxSizeBytes = ini_parse_quantity(ini_get('post_max_size'));
$uploadMaxSizeBytes = ini_parse_quantity(ini_get('upload_max_filesize'));
return min($postMaxSizeBytes, $uploadMaxSizeBytes);
}

/**
11 changes: 7 additions & 4 deletions app/code/core/Mage/ImportExport/Model/Export.php
Original file line number Diff line number Diff line change
@@ -65,7 +65,9 @@ protected function _getEntityAdapter()

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

if (isset($validWriters[$this->getFileFormat()])) {
try {
$this->_writer = Mage::getModel($validWriters[$this->getFileFormat()]['model']);
/** @var Mage_ImportExport_Model_Export_Adapter_Abstract $_writer */
$_writer = Mage::getModel($validWriters[$this->getFileFormat()]['model']);
$this->_writer = $_writer;
} catch (Exception $e) {
Mage::logException($e);
Mage::throwException(
@@ -185,8 +189,7 @@ public function exportFile()
Mage::throwException(
Mage::helper('importexport')->__('There is no data for export')
);
}
if ($result['rows']) {
} else {
$this->addLogComment([
Mage::helper('importexport')->__('Exported %s rows.', $result['rows']),
Mage::helper('importexport')->__('Export has been done.')
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ abstract class Mage_ImportExport_Model_Export_Entity_Abstract
/**
* Entity type id.
*
* @var int
* @var string|null
*/
protected $_entityTypeId;

@@ -170,7 +170,10 @@ public function __construct()
{
$entityCode = $this->getEntityTypeCode();
$this->_entityTypeId = Mage::getSingleton('eav/config')->getEntityType($entityCode)->getEntityTypeId();
$this->_connection = Mage::getSingleton('core/resource')->getConnection('write');

/** @var Varien_Db_Adapter_Pdo_Mysql $_connection */
$_connection = Mage::getSingleton('core/resource')->getConnection('write');
$this->_connection = $_connection;
}

/**
@@ -436,7 +439,7 @@ abstract public function getEntityTypeCode();
/**
* Entity type ID getter.
*
* @return int
* @return string|null
*/
public function getEntityTypeId()
{
8 changes: 5 additions & 3 deletions app/code/core/Mage/ImportExport/Model/Import.php
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ class Mage_ImportExport_Model_Import extends Mage_ImportExport_Model_Abstract
/**
* Entity invalidated indexes.
*
* @var Mage_ImportExport_Model_Import_Entity_Abstract
* @var array<string, array<int, string>>
*/
protected static $_entityInvalidatedIndexes = [
'catalog_product' => [
@@ -80,7 +80,9 @@ protected function _getEntityAdapter()

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

$row[$colName] = $m[1] . ($m[2] + $size) . ($regExpType == 'middle' ? $m[3] : '');
$row[$colName] = $m[1] . ((int) $m[2] + $size) . ($regExpType == 'middle' ? $m[3] : '');
}
}
$writer->writeRow($row);
13 changes: 8 additions & 5 deletions app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ abstract class Mage_ImportExport_Model_Import_Entity_Abstract
/**
* DB connection.
*
* @var Varien_Convert_Adapter_Interface
* @var Varien_Db_Adapter_Pdo_Mysql
*/
protected $_connection;

@@ -54,7 +54,7 @@ abstract class Mage_ImportExport_Model_Import_Entity_Abstract
/**
* Entity type id.
*
* @var int
* @var string|null
*/
protected $_entityTypeId;

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

public function __construct()
{
$entityType = Mage::getSingleton('eav/config')->getEntityType($this->getEntityTypeCode());
$entityType = Mage::getSingleton('eav/config')->getEntityType($this->getEntityTypeCode());
$this->_entityTypeId = $entityType->getEntityTypeId();
$this->_dataSourceModel = Mage_ImportExport_Model_Import::getDataSourceModel();
$this->_connection = Mage::getSingleton('core/resource')->getConnection('write');

/** @var Varien_Db_Adapter_Pdo_Mysql $_connection */
$_connection = Mage::getSingleton('core/resource')->getConnection('write');
$this->_connection = $_connection;
}

/**
@@ -398,7 +401,7 @@ abstract public function getEntityTypeCode();
/**
* Entity type ID getter.
*
* @return int
* @return string|null
*/
public function getEntityTypeId()
{
Original file line number Diff line number Diff line change
@@ -369,6 +369,7 @@ protected function _saveCustomers()
$entityRowsIn = [];
$entityRowsUp = [];
$attributes = [];
$entityId = null;

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

Original file line number Diff line number Diff line change
@@ -416,7 +416,7 @@ class Mage_ImportExport_Model_Import_Entity_Product extends Mage_ImportExport_Mo
/**
* url_key attribute id
*
* @var int
* @var string|false|null
*/
protected $_urlKeyAttributeId;

@@ -901,6 +901,8 @@ protected function _saveCustomOptions()
'updated_at' => Varien_Date::now()
];
}

$prevOptionId = 0;
if ($rowIsMain) {
$solidParams = [
'option_id' => $nextOptionId,
@@ -1152,6 +1154,7 @@ protected function _saveLinks()
$productIds = [];
$linkRows = [];
$positionRows = [];
$sku = null;

foreach ($bunch as $rowNum => $rowData) {
$this->_filterRowData($rowData);
@@ -1362,6 +1365,7 @@ protected function _saveProducts()
$tierPrices = [];
$groupPrices = [];
$mediaGallery = [];
$rowSku = null;
$uploadedGalleryFiles = [];
$previousType = null;
$previousAttributeSet = null;
@@ -2207,7 +2211,7 @@ public function getAffectedEntityIds()
/**
* Get product url_key attribute id
*
* @return null|int
* @return string|false|null
*/
protected function _getUrlKeyAttributeId()
{
Original file line number Diff line number Diff line change
@@ -356,6 +356,8 @@ public function saveData()
$newSku = $this->_entityModel->getNewSku();
$oldSku = $this->_entityModel->getOldSku();
$productSuperData = [];
$productSuperAttrId = null;
$productId = null;
$productData = null;
/** @var Mage_ImportExport_Model_Resource_Helper_Mysql4 $helper */
$helper = Mage::getResourceHelper('importexport');
Original file line number Diff line number Diff line change
@@ -65,6 +65,7 @@ public function saveData()
$newSku = $this->_entityModel->getNewSku();
$oldSku = $this->_entityModel->getOldSku();
$attributes = [];
$productData = [];

// pre-load attributes parameters
$select = $connection->select()
@@ -101,6 +102,7 @@ public function saveData()
} else {
continue;
}

$scope = $this->_entityModel->getRowScope($rowData);
if (Mage_ImportExport_Model_Import_Entity_Product::SCOPE_DEFAULT == $scope) {
$productData = $newSku[$rowData[Mage_ImportExport_Model_Import_Entity_Product::COL_SKU]];
2 changes: 1 addition & 1 deletion app/code/core/Mage/Shipping/Model/Carrier/Abstract.php
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ abstract class Mage_Shipping_Model_Carrier_Abstract extends Varien_Object
/**
* Rate result data
*
* @var Mage_Shipping_Model_Rate_Result|null
* @var Mage_Shipping_Model_Rate_Result|Mage_Shipping_Model_Tracking_Result|null
*/
protected $_result;

2 changes: 1 addition & 1 deletion app/code/core/Mage/Uploader/Helper/File.php
Original file line number Diff line number Diff line change
@@ -703,7 +703,7 @@ public function getUploadMaxSize()
/**
* Get max upload size
*
* @return mixed
* @return string
*/
public function getDataMaxSize()
{
17 changes: 13 additions & 4 deletions app/code/core/Mage/Usa/Model/Shipping/Carrier/Usps.php
Original file line number Diff line number Diff line change
@@ -85,10 +85,18 @@ class Mage_Usa_Model_Shipping_Carrier_Usps extends Mage_Usa_Model_Shipping_Carri
*/
protected $_rawRequest = null;


/**
* Raw rate tracking request data
*
* @var Varien_Object|null
*/
protected $_rawTrackRequest = null;

/**
* Rate result data
*
* @var Mage_Shipping_Model_Rate_Result|null
* @var Mage_Shipping_Model_Rate_Result|Mage_Shipping_Model_Tracking_Result|null
*/
protected $_result = null;

@@ -425,7 +433,7 @@ protected function _getXmlQuotes()
*
* @link http://www.usps.com/webtools/htm/Rate-Calculators-v2-3.htm
* @param string $response
* @return Mage_Shipping_Model_Rate_Result
* @return Mage_Shipping_Model_Rate_Result|void
*/
protected function _parseXmlResponse($response)
{
@@ -512,6 +520,7 @@ protected function _parseXmlResponse($response)
}
}
}

/**
* Get configuration data of carrier
*
@@ -901,7 +910,7 @@ public function getTracking($trackingData)
/**
* Set tracking request
*
* @return null
* @return void
*/
protected function setTrackingRequest()
{
@@ -960,7 +969,7 @@ protected function _getXmlTracking($trackingData)
*
* @param array $trackingValue
* @param string $response
* @return null
* @return void
*/
protected function _parseXmlTrackingResponse($trackingValue, $response)
{
Loading

0 comments on commit cabdc8b

Please sign in to comment.