Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some phpStan fixes #4290

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
282 changes: 6 additions & 276 deletions .phpstan.dist.baseline.neon

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -924,9 +924,11 @@ public static function log($message, $level = null, $file = '', $forceLog = fals
}

if (is_array($message) || is_object($message)) {
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$message = print_r($message, true);
}

// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
$message = addcslashes($message, '<?');
$loggers[$file]->log($message, $level);
} catch (Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Admin/Model/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function _construct()
}

/**
* @return array|bool
* @return array|true
* @throws Exception
* @throws Zend_Validate_Exception
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ protected function _getRequiredAttributesIds()
*/
public function escapeJs($string)
{
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
return addcslashes($string, "'\r\n\\");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function render(Varien_Object $row)

protected function _getEscapedValue($value)
{
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
return addcslashes(htmlspecialchars($value), '\\\'');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public function getJsTemplateName()
if ($templateCode === null) {
return '';
}
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
return addcslashes($this->escapeHtml($templateCode), "\"\r\n\\");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function render(Varien_Object $row)

protected function _getEscapedValue($value)
{
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
return addcslashes(htmlspecialchars($value), '\\\'');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function render(Varien_Object $row)

protected function _getEscapedValue($value)
{
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
return addcslashes(htmlspecialchars($value), '\\\'');
}

Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Api2/Model/Route/ApiType.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ class Mage_Api2_Model_Route_ApiType extends Mage_Api2_Model_Route_Abstract imple
* @param Zend_Translate|null $translator Translator to use for this instance
* @param mixed $locale
*/
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
public function __construct(
$route,
$defaults = [],
$reqs = [],
?Zend_Translate $translator = null,
$locale = null
) {
// phpcs:ignore Ecg.Security.ForbiddenFunction.Found
parent::__construct([Mage_Api2_Model_Route_Abstract::PARAM_ROUTE => str_replace('.php', '', basename(getenv('SCRIPT_FILENAME'))) . '/:api_type']);
}
}
1 change: 0 additions & 1 deletion app/code/core/Mage/Bundle/Model/Product/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public function getTotalBundleItemsPrice($product, $qty = null)
$selectionIds = unserialize($customOption->getValue(), ['allowed_classes' => false]);
/** @var Mage_Bundle_Model_Product_Type $productType */
$productType = $product->getTypeInstance(true);
/** @var Mage_Bundle_Model_Resource_Selection_Collection $selections */
$selections = $productType->getSelectionsByIds($selectionIds, $product);
$selections->addTierPriceData();
Mage::dispatchEvent('prepare_catalog_product_collection_prices', [
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Captcha/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function isEnabled(): bool
* Get Captcha
*
* @param string $formId
* @return Mage_Captcha_Model_Interface
* @return Mage_Captcha_Model_Zend
*/
public function getCaptcha($formId)
{
Expand All @@ -76,7 +76,7 @@ public function getCaptcha($formId)
/**
* Returns value of the node with respect to current area (frontend or backend)
*
* @param string $id The last part of XML_PATH_$area_CAPTCHA_ constant (case insensitive)
* @param string $id The last part of XML_PATH_$area_CAPTCHA_ constant (case-insensitive)
* @param Mage_Core_Model_Store $store
* @return Mage_Core_Model_Config_Element
*/
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Catalog/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Mage_Catalog_Helper_Data extends Mage_Core_Helper_Abstract
/**
* Breadcrumb Path cache
*
* @var string
* @var string|array<string, array<string, string|null>>
*/
protected $_categoryPath;

Expand Down Expand Up @@ -236,7 +236,7 @@ public function isPriceGlobal()
/**
* Indicate whether to save URL Rewrite History or not (create redirects to old URLs)
*
* @param int $storeId Store View
* @param null|string|bool|int|Mage_Core_Model_Store $storeId Store View
* @return bool
*/
public function shouldSaveUrlRewritesHistory($storeId = null)
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Api/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function _isAllowedAttribute($attribute, $attributes = null)

/**
* Retrieves store id from store code, if no store id specified,
* it use seted session or admin store
* it uses set session or admin store
*
* @param string|int $store
* @return int
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,14 @@ public function getLayoutUpdateHandle()
/**
* Return store id.
*
* If store id is underfined for category return current active store id
* If store id is undefined for category return current active store id
*
* @return int
*/
public function getStoreId()
{
if ($this->hasData('store_id')) {
return $this->_getData('store_id');
return (int)$this->_getData('store_id');
}
return Mage::app()->getStore()->getId();
}
Expand Down
6 changes: 6 additions & 0 deletions app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ public function parse()
$importIds = $batchImportModel->getIdCollection();

foreach ($importIds as $importId) {
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
$batchImportModel->load($importId);
$importData = $batchImportModel->getBatchData();

Expand Down Expand Up @@ -511,6 +512,7 @@ public function save()
// if product is new, create default values first
if (!$model->getId()) {
$new = true;
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
$model->save();

// if new product and then store is not default
Expand All @@ -520,6 +522,7 @@ public function save()
$default = Mage::getModel('catalog/product');
$default->setData($data);
$default->setStoreId(0);
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
$default->save();
unset($default);
} // end
Expand All @@ -533,6 +536,7 @@ public function save()
$storeId
);
}
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
$model->save();
}

Expand Down Expand Up @@ -564,6 +568,7 @@ public function save()
}
}
}
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
$stockItem->save();
unset($data);
unset($stockItem);
Expand Down Expand Up @@ -734,6 +739,7 @@ public function saveRow(array $importData)
if (!in_array($website->getId(), $websiteIds)) {
$websiteIds[] = $website->getId();
}
// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
} catch (Exception $e) {
}
}
Expand Down
14 changes: 8 additions & 6 deletions app/code/core/Mage/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
* @method string getMetaDescription()
* @method string getMetaKeyword()
* @method string getMetaTitle()
* @method $this hasMsrpEnabled(bool $value)
* @method $this hasMsrpEnabled()
* @method bool getMsrpEnabled()
* @method string getMsrpDisplayActualPriceType()
*
Expand Down Expand Up @@ -217,7 +217,7 @@
* @method $this setStoreIds(array $storeIds)
* @method array getSwatchPrices()
*
* @method int getTaxClassId()
* @method string getTaxClassId()
* @method string getThumbnail()
* @method float|null getTaxPercent()
* @method $this setTaxPercent(float|null $value)
Expand Down Expand Up @@ -365,7 +365,7 @@ protected function _initOldFieldsMap()
public function getStoreId()
{
if ($this->hasData('store_id')) {
return $this->getData('store_id');
return (int)$this->getData('store_id');
}
return Mage::app()->getStore()->getId();
}
Expand Down Expand Up @@ -417,7 +417,7 @@ public function validate()
/**
* Get product name
*
* @return string
* @return string|null
*/
public function getName()
{
Expand All @@ -442,16 +442,18 @@ public function getPrice()
* Set Price calculation flag
*
* @param bool $calculate
* @return $this
*/
public function setPriceCalculation($calculate = true)
{
$this->_calculatePrice = $calculate;
return $this;
}

/**
* Get product type identifier
*
* @return string
* @return string|null
*/
public function getTypeId()
{
Expand Down Expand Up @@ -876,7 +878,7 @@ public function cleanCache()
/**
* Get product price model
*
* @return Mage_Catalog_Model_Product_Type_Price|Mage_Bundle_Model_Product_Price
* @return Mage_Bundle_Model_Product_Price
*/
public function getPriceModel()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,6 @@ public function addAttributeToSelect($attribute = '*')
return $this;
}

/**
* Retrieve resource instance
*
* @inheritDoc
*/
public function getResource()
{
return parent::getResource();
}

/**
* Add attribute to sort order
*
Expand Down Expand Up @@ -325,6 +315,7 @@ public function addPathsFilter($paths)
$select = $this->getSelect();
$cond = [];
foreach ($paths as $path) {
// phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql
$cond[] = $this->getResource()->getReadConnection()->quoteInto('main_table.path LIKE ?', "$path%");
}
if ($cond) {
Expand Down
9 changes: 7 additions & 2 deletions app/code/core/Mage/Catalog/Model/Resource/Category/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function __construct()
*/
public function setStoreId($storeId)
{
$this->_storeId = (int) $storeId;
$this->_storeId = $storeId;
return $this;
}

Expand Down Expand Up @@ -467,13 +467,15 @@ public function loadByIds($ids, $addCollectionData = true, $updateAnchorProductC
->where('entity_id IN (?)', $ids);
$where = [$levelField . '=0' => true];

// phpcs:ignore Ecg.Performance.FetchAll.Found
foreach ($this->_conn->fetchAll($select) as $item) {
if (!preg_match("#^[0-9\/]+$#", $item['path'])) {
$item['path'] = '';
}
$pathIds = explode('/', $item['path']);
$level = (int)$item['level'];
while ($level > 0) {
// phpcs:ignore Ecg.Performance.Loop.ArraySize
$pathIds[count($pathIds) - 1] = '%';
$path = implode('/', $pathIds);
$where["$levelField=$level AND $pathField LIKE '$path'"] = true;
Expand All @@ -493,6 +495,7 @@ public function loadByIds($ids, $addCollectionData = true, $updateAnchorProductC
$select->where(implode(' OR ', $where));

// get array of records and add them as nodes to the tree
// phpcs:ignore Ecg.Performance.FetchAll.Found
$arrNodes = $this->_conn->fetchAll($select);
if (!$arrNodes) {
return false;
Expand Down Expand Up @@ -535,6 +538,7 @@ public function loadBreadcrumbsArray($path, $addCollectionData = true, $withRoot
$select
->where('e.entity_id IN(?)', $pathIds)
->order($this->_conn->getLengthSql('e.path') . ' ' . Varien_Db_Select::SQL_ASC);
// phpcs:ignore Ecg.Performance.FetchAll.Found
$result = $this->_conn->fetchAll($select);
$this->_updateAnchorProductCount($result);
}
Expand All @@ -557,7 +561,7 @@ protected function _updateAnchorProductCount(&$data)

/**
* Obtain select for categories with attributes.
* By default everything from entity table is selected
* By default, everything from entity table is selected
* + name, is_active and is_anchor
* Also the correct product_count is selected, depending on is the category anchor or not.
*
Expand Down Expand Up @@ -623,6 +627,7 @@ protected function _createCollectionDataSelect($sorted = true, $optionalAttribut
['COUNT(DISTINCT scp.product_id)']
)
->where('see.entity_id = e.entity_id')
// phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql
->orWhere('see.path LIKE ?', $subConcat);
$select->columns(['product_count' => $subSelect]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function getStoreId()
if ($dataObject) {
return $dataObject->getStoreId();
}
return $this->getData('store_id');
return (int)$this->getData('store_id');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function setShouldSaveRewritesHistory($flag)
/**
* Indicate whether to save URL Rewrite History or not (create redirects to old URLs)
*
* @param int $storeId Store View
* @param null|string|bool|int|Mage_Core_Model_Store $storeId Store View
* @return bool
*/
public function getShouldSaveRewritesHistory($storeId = null)
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Checkout/Model/Api/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function _isQuoteExist($quoteId)

/**
* Retrieves store id from store code, if no store id specified,
* it use set session or admin store
* it uses set session or admin store
*
* @param string|int $store
* @return int
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Checkout/Model/Cart/Product/Api/V2.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Mage_Checkout_Model_Cart_Product_Api_V2 extends Mage_Checkout_Model_Cart_P
/**
* Return an Array of Object attributes.
*
* @param mixed $data
* @param object|array $data
* @return array
*/
protected function _prepareProductsData($data)
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public function getVersionHash(Mage_Core_Model_Encryption $encryptionModel)
/**
* Retrieve store identifier
*
* @param mixed $store
* @param bool|int|Mage_Core_Model_Store|null|string $store
* @return int
*/
public function getStoreId($store = null)
Expand Down
Loading
Loading