Skip to content

PhpStan: some fixes #4705

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

Merged
merged 24 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2,162 changes: 28 additions & 2,134 deletions .phpstan.dist.baseline.neon

Large diffs are not rendered by default.

25 changes: 6 additions & 19 deletions .phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ parameters:
- app/design/frontend/base/default/template/catalog/product/view/price.phtml
- app/design/frontend/base/default/template/catalog/product/widget/link/link_block.phtml
- app/design/frontend/base/default/template/catalog/product/widget/link/link_inline.phtml
- app/design/frontend/base/default/template/catalog/product/widget/new/column/new_default_list.phtml
- app/design/frontend/base/default/template/catalog/product/widget/new/column/new_images_list.phtml
- app/design/frontend/base/default/template/catalog/product/widget/new/column/new_names_list.phtml
- app/design/frontend/base/default/template/catalog/product/widget/new/content/new_grid.phtml
- app/design/frontend/base/default/template/catalog/product/widget/new/content/new_list.phtml
- app/design/frontend/base/default/template/checkout/cart/render/default.phtml
- app/design/frontend/base/default/template/checkout/cart/render/simple.phtml
- app/design/frontend/base/default/template/cms/widget/link/link_block.phtml
Expand All @@ -132,28 +127,20 @@ parameters:
- app/design/frontend/base/default/template/directory/currency/switch.phtml
- app/design/frontend/base/default/template/page/redirect.phtml
- app/design/frontend/base/default/template/paypal/hss/review/button.phtml
- app/design/frontend/base/default/template/reports/widget/compared/column/compared_default_list.phtml
- app/design/frontend/base/default/template/reports/widget/compared/column/compared_images_list.phtml
- app/design/frontend/base/default/template/reports/widget/compared/column/compared_names_list.phtml
- app/design/frontend/base/default/template/reports/widget/compared/content/compared_grid.phtml
- app/design/frontend/base/default/template/reports/widget/compared/content/compared_list.phtml
- app/design/frontend/rwd/default/template/catalog/product/widget/new/column/new_default_list.phtml
- app/design/frontend/rwd/default/template/catalog/product/widget/new/column/new_images_list.phtml
- app/design/frontend/rwd/default/template/catalog/product/widget/new/column/new_names_list.phtml
- app/design/frontend/rwd/default/template/catalog/product/widget/new/content/new_list.phtml
- app/design/frontend/rwd/default/template/checkout/cart/render/default.phtml
- app/design/frontend/rwd/default/template/checkout/cart/render/simple.phtml
- app/design/frontend/rwd/default/template/customer/form/address.phtml
- app/design/frontend/rwd/default/template/customer/form/changepassword.phtml
- app/design/frontend/rwd/default/template/paypal/express/review/address.phtml
- app/design/frontend/rwd/default/template/reports/widget/compared/column/compared_default_list.phtml
- app/design/frontend/rwd/default/template/reports/widget/compared/column/compared_images_list.phtml
- app/design/frontend/rwd/default/template/reports/widget/compared/column/compared_names_list.phtml
- app/design/frontend/rwd/default/template/reports/widget/compared/content/compared_grid.phtml
- app/design/frontend/rwd/default/template/reports/widget/compared/content/compared_list.phtml
- app/design/install/default/default/template/page.phtml
-
identifier: phpunit.coversMethod
-
identifier: variable.undefined
paths:
- app/design/*/*/template/*
- errors/*
- lib/Varien/*
tmpDir: .phpstan.cache
level: 5
checkFunctionNameCase: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getAddressId()
/**
* Return billing address object
*
* @return Mage_Customer_Model_Address
* @return Mage_Sales_Model_Quote_Address
*/
public function getAddress()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Mage_Adminhtml_Block_Sales_Order_Create_Giftmessage_Form extends Mage_Admi
/**
* Entity for editing of gift message
*
* @var Mage_Eav_Model_Entity_Abstract
* @var Varien_Object
*/
protected $_entity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function getWebsiteId()
/**
* Set current website
*
* @param int $name
* @param string $name
* @return $this
*/
public function setConditionName($name)
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Widget/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@ public function getRowspan($item, $column)

/**
* @param string|object $column
* @param string $value
* @param string|bool $value
* @return bool|$this
*/
public function isColumnGrouped($column, $value = null)
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Adminhtml/Helper/Sales.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public function displayPrices($dataObject, $basePrice, $price, $strong = false,
/**
* Filter collection by removing not available product types
*
* @param Mage_Core_Model_Resource_Db_Collection_Abstract $collection
* @return Mage_Core_Model_Resource_Db_Collection_Abstract
* @param Mage_Catalog_Model_Resource_Product_Collection $collection
* @return Mage_Catalog_Model_Resource_Product_Collection
*/
public function applySalableProductTypesFilter($collection)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Mage_Adminhtml_Customer_Wishlist_Product_Composite_WishlistController exte
/**
* Wishlist item we're working with
*
* @var Mage_Wishlist_Model_Wishlist
* @var Mage_Wishlist_Model_Item
*/
protected $_wishlistItem = null;

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Api/Model/Server/Adapter/Soap.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Mage_Api_Model_Server_Adapter_Soap extends Varien_Object implements Mage_A
/**
* Soap server
*
* @var SoapServer
* @var Zend_Soap_Server
*/
protected $_soap = null;

Expand Down
4 changes: 3 additions & 1 deletion app/code/core/Mage/Api2/Model/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public function __construct($uri = null)
protected function _getInterpreter()
{
if ($this->_interpreter === null) {
$this->_interpreter = Mage_Api2_Model_Request_Interpreter::factory($this->getContentType());
/** @var Mage_Api2_Model_Request_Interpreter_Interface $factory */
$factory = Mage_Api2_Model_Request_Interpreter::factory($this->getContentType());
$this->_interpreter = $factory;
}
return $this->_interpreter;
}
Expand Down
14 changes: 9 additions & 5 deletions app/code/core/Mage/Api2/Model/Resource/Validator/Eav.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,19 @@ public function __construct($options)
if (empty($validationConfig[$userType]['entity_model'])) {
throw new Exception("Config parameter 'entity' is wrong.");
}
$this->_entity = Mage::getModel($validationConfig[$userType]['entity_model']);
if (empty($this->_entity) || !$this->_entity instanceof Mage_Core_Model_Abstract) {

$entityModel = Mage::getModel($validationConfig[$userType]['entity_model']);
if (empty($entityModel) || !$entityModel instanceof Mage_Core_Model_Abstract) {
throw new Exception('Entity is not model.');
}
$this->_entity = $entityModel;

$this->_eavForm = Mage::getModel($this->_formPath);
if (empty($this->_eavForm) || !$this->_eavForm instanceof Mage_Eav_Model_Form) {
throw new Exception("Eav form '{$this->_formPath}' is not found.");
$formModel = Mage::getModel($this->_formPath);
if (empty($formModel) || !$formModel instanceof Mage_Eav_Model_Form) {
throw new Exception("Eav form '{$formModel}' is not found.");
}
$this->_eavForm = $formModel;

$this->_eavForm->setEntity($this->_entity)
->setFormCode($this->_formCode)
->ignoreInvisible(false);
Expand Down
1 change: 0 additions & 1 deletion app/code/core/Mage/Api2/Model/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ protected function _authenticate(Mage_Api2_Model_Request $request)
/**
* Set auth user
*
* @throws Exception
* @return $this
*/
protected function _setAuthUser(Mage_Api2_Model_Auth_User_Abstract $authUser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function responseAction()
$paymentMethod = Mage::getModel('authorizenet/directpost');

$result = [];
$params = [];
if (!empty($data['x_invoice_num'])) {
$result['x_invoice_num'] = $data['x_invoice_num'];
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Bundle/Model/Product/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ public function getSelectionFinalPrice(
* @param Mage_Catalog_Model_Product $bundleProduct
* @param Mage_Catalog_Model_Product $selectionProduct
* @param float $bundleQty
* @param float $selectionQty
* @param float|null $selectionQty
* @param bool $multiplyQty
* @param bool $takeTierPrice
* @return float
Expand Down
3 changes: 2 additions & 1 deletion app/code/core/Mage/Bundle/Model/Resource/Price/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ protected function _reindexProduct($productId, $priceType)
$salableStatus = $this->getProductsSalableStatus($selectionProducts, $website);
$priceData = $this->getProductsPriceData($productId, $website);
$priceData = $priceData[$productId];
$basePrice = 0;

/** @var Mage_Customer_Model_Group $group */
foreach ($this->_getCustomerGroups() as $group) {
Expand All @@ -222,7 +223,7 @@ protected function _reindexProduct($productId, $priceType)
$group,
);

if ($priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) {
if (isset($customOptions) && $priceType == Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) {
[$minPrice, $maxPrice] =
$this->_calculateCustomOptions($customOptions, $basePrice, $minPrice, $maxPrice);
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Catalog/Block/Product/List/Crosssell.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Mage_Catalog_Block_Product_List_Crosssell extends Mage_Catalog_Block_Produ
/**
* Crosssell item collection
*
* @var Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection
* @var Mage_Catalog_Model_Resource_Product_Link_Product_Collection
*/
protected $_itemCollection;

Expand Down Expand Up @@ -77,7 +77,7 @@ protected function _beforeToHtml()
/**
* Retrieve crosssell items collection
*
* @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection
* @return Mage_Catalog_Model_Resource_Product_Link_Product_Collection
*/
public function getItems()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected function _getHtmlSelect($name, $value = null)
* Add Leading Zeros to number less than 10
*
* @param int $value
* @return string
* @return int|string
*/
protected function _getValueWithLeadingZeros($value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ public function isLastPage()
*/
public function getPages()
{
$pages = [];
$start = 1;
$finish = 1;

if ($this->getLastPageNum() <= $this->_displayPages) {
$pages = range(1, $this->getLastPageNum());
} else {
Expand All @@ -212,7 +214,6 @@ public function getPages()
$start = ($this->getCurrentPage() - $half) + 1;
$finish = ($start + $this->_displayPages) - 1;
} elseif ($this->getCurrentPage() < $half) {
$start = 1;
$finish = $this->_displayPages;
} elseif ($this->getCurrentPage() > ($this->getLastPageNum() - $half)) {
$finish = $this->getLastPageNum();
Expand Down
4 changes: 3 additions & 1 deletion app/code/core/Mage/Catalog/Block/Product/Widget/New.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ public function getPagerHtml()
{
if ($this->showPager()) {
if (!$this->_pager) {
$this->_pager = $this->getLayout()
/** @var Mage_Catalog_Block_Product_Widget_Html_Pager $block */
$block = $this->getLayout()
->createBlock('catalog/product_widget_html_pager', 'widget.new.product.list.pager');

$this->_pager = $block;
$this->_pager->setUseContainer(true)
->setShowAmounts(true)
->setShowPerPage(false)
Expand Down
5 changes: 3 additions & 2 deletions app/code/core/Mage/Catalog/Block/Seo/Sitemap/Tree/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ public function isLastPage()
*/
public function getPages()
{
$pages = [];
$start = 1;
$finish = 1;

if ($this->getLastPageNum() <= $this->_displayPages) {
$pages = range(1, $this->getLastPageNum());
} else {
Expand All @@ -175,7 +177,6 @@ public function getPages()
$start = ($this->getCurrentPage() - $half) + 1;
$finish = ($start + $this->_displayPages) - 1;
} elseif ($this->getCurrentPage() < $half) {
$start = 1;
$finish = $this->_displayPages;
} elseif ($this->getCurrentPage() > ($this->getLastPageNum() - $half)) {
$finish = $this->getLastPageNum();
Expand Down
6 changes: 4 additions & 2 deletions app/code/core/Mage/Catalog/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,14 @@ public function isUrlDirectivesParsingAllowed()
/**
* Retrieve template processor for catalog content
*
* @return false|Mage_Core_Model_Abstract
* @return Varien_Filter_Template
*/
public function getPageTemplateProcessor()
{
$model = (string) Mage::getConfig()->getNode(self::XML_PATH_CONTENT_TEMPLATE_FILTER);
return Mage::getModel($model);
/** @var Varien_Filter_Template $model */
$model = Mage::getModel($model);
return $model;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Helper/Product/Compare.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Mage_Catalog_Helper_Product_Compare extends Mage_Core_Helper_Url
/**
* Product Compare Items Collection
*
* @var Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection
* @var Mage_Catalog_Model_Resource_Product_Compare_Item_Collection
*/
protected $_itemCollection;

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Design.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ protected function _applyDesign($designUpdateData, $calledFrom = 0, $loaded = fa
} elseif ($designUpdateData instanceof Mage_Catalog_Model_Category) {
$_category = &$designUpdateData;
}
if ($_category && $_category->getId()) {
if (isset($_category) && $_category->getId()) {
$_designUpdateData = array_merge(
$_designUpdateData,
$_category->getResource()->getDesignUpdateData($_category),
Expand Down
10 changes: 5 additions & 5 deletions app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,9 @@ public function getClearLinkText()
* Load range of product prices
*
* @param int $limit
* @param null|int $offset
* @param null|int $lowerPrice
* @param null|int $upperPrice
* @param int|null $offset
* @param float|null $lowerPrice
* @param float|null $upperPrice
* @return array
*/
public function loadPrices($limit, $offset = null, $lowerPrice = null, $upperPrice = null)
Expand All @@ -549,7 +549,7 @@ public function loadPrices($limit, $offset = null, $lowerPrice = null, $upperPri
*
* @param float $price
* @param int $index
* @param null|int $lowerPrice
* @param float|null $lowerPrice
* @return array|false
*/
public function loadPreviousPrices($price, $index, $lowerPrice = null)
Expand All @@ -567,7 +567,7 @@ public function loadPreviousPrices($price, $index, $lowerPrice = null)
*
* @param float $price
* @param int $rightIndex
* @param null|int $upperPrice
* @param float|null $upperPrice
* @return array|false
*/
public function loadNextPrices($price, $rightIndex, $upperPrice = null)
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Product/Type/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function getEditableAttributes($product = null)
/**
* Retrieve product attribute by identifier
*
* @param int $attributeId
* @param int|string $attributeId
* @param Mage_Catalog_Model_Product $product
* @return Mage_Eav_Model_Entity_Attribute_Abstract|null
*/
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Product/Type/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public function getFormatedPrice($product)
* Apply options price
*
* @param Mage_Catalog_Model_Product $product
* @param int $qty
* @param float $qty
* @param float $finalPrice
* @return float
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ public function addIdFilter($categoryIds)
$condition = ['in' => $ids];
}
}
$this->addFieldToFilter('entity_id', $condition);
if (isset($condition)) {
$this->addFieldToFilter('entity_id', $condition);
}

return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,9 +964,15 @@ public function reindexAll()
* Clean up temporary tables
*/
$this->clearTemporaryIndexTable();
$idxAdapter->delete($enabledTable);
$idxAdapter->delete($anchorTable);
$idxAdapter->delete($anchorProductsTable);
if (isset($enabledTable)) {
$idxAdapter->delete($enabledTable);
}
if (isset($anchorTable)) {
$idxAdapter->delete($anchorTable);
}
if (isset($anchorProductsTable)) {
$idxAdapter->delete($anchorProductsTable);
}
$this->commit();
} catch (Exception $e) {
$this->rollBack();
Expand Down
Loading
Loading