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

PhpStan: some fixes #4705

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
272 changes: 1 addition & 271 deletions .phpstan.dist.baseline.neon

Large diffs are not rendered by default.

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
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
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
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
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
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ class Mage_CatalogInventory_Block_Adminhtml_Form_Field_Minsaleqty extends Mage_A
protected function _getGroupRenderer()
{
if (!$this->_groupRenderer) {
$this->_groupRenderer = $this->getLayout()->createBlock(
/** @var Mage_CatalogInventory_Block_Adminhtml_Form_Field_Customergroup $block */
$block = $this->getLayout()->createBlock(
'cataloginventory/adminhtml_form_field_customergroup',
'',
['is_render_to_js_template' => true],
);
$this->_groupRenderer = $block;
$this->_groupRenderer->setClass('customer_group_select');
$this->_groupRenderer->setExtraParams('style="width:120px"');
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Checkout/Block/Cart/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Mage_Checkout_Block_Cart_Shipping extends Mage_Checkout_Block_Cart_Abstrac
/**
* Address Model
*
* @var array
* @var Mage_Sales_Model_Quote_Address|array
*/
protected $_address = [];
Comment on lines -38 to 40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
* Get Address Model
*
* @return Mage_Sales_Model_Quote_Address
*/
public function getAddress()
{
if (empty($this->_address)) {
$this->_address = $this->getQuote()->getShippingAddress();
}
return $this->_address;
}

$_address cannot be an array:

Suggested change
* @var array
* @var Mage_Sales_Model_Quote_Address|array
*/
protected $_address = [];
* @var Mage_Sales_Model_Quote_Address
*/
protected $_address;

What do you think?


Expand Down
4 changes: 3 additions & 1 deletion app/code/core/Mage/Checkout/Block/Onepage/Billing.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ public function getSaveUrl() {}
protected function _getTaxvat()
{
if (!$this->_taxvat) {
$this->_taxvat = $this->getLayout()->createBlock('customer/widget_taxvat');
/** @var Mage_Customer_Block_Widget_Taxvat $block */
$block = $this->getLayout()->createBlock('customer/widget_taxvat');
$this->_taxvat = $block;
}

return $this->_taxvat;
Expand Down
8 changes: 4 additions & 4 deletions app/code/core/Mage/Checkout/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function canOnepageCheckout()
* Get sales item (quote item, order item etc) price including tax based on row total and tax amount
* excluding weee tax
*
* @param Mage_Core_Model_Abstract $item
* @param Mage_Core_Model_Abstract|Varien_Object $item
* @return float
*/
public function getPriceInclTax($item)
Expand All @@ -118,7 +118,7 @@ public function getPriceInclTax($item)
/**
* Get sales item (quote item, order item etc) row total price including tax
*
* @param Mage_Core_Model_Abstract $item
* @param Mage_Core_Model_Abstract|Varien_Object $item
* @return float
*/
public function getSubtotalInclTax($item)
Expand Down Expand Up @@ -146,7 +146,7 @@ protected function _getWeeeHelper()
/**
* Get the base price of the item including tax , excluding weee
*
* @param Mage_Core_Model_Abstract $item
* @param Mage_Core_Model_Abstract|Varien_Object $item
* @return float
*/
public function getBasePriceInclTax($item)
Expand All @@ -159,7 +159,7 @@ public function getBasePriceInclTax($item)
/**
* Get sales item (quote item, order item etc) row total price including tax excluding wee
*
* @param Mage_Core_Model_Abstract $item
* @param Mage_Core_Model_Abstract|Varien_Object $item
* @return float
*/
public function getBaseSubtotalInclTax($item)
Expand Down
4 changes: 3 additions & 1 deletion app/code/core/Mage/Core/Controller/Varien/Front.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ public function dispatch()
protected function _getRequestRewriteController()
{
$className = (string) Mage::getConfig()->getNode('global/request_rewrite/model');
return Mage::getSingleton('core/factory')->getModel($className, [
/** @var Mage_Core_Model_Url_Rewrite_Request $model */
$model = Mage::getSingleton('core/factory')->getModel($className, [
'routers' => $this->getRouters(),
]);
return $model;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Helper/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class Mage_Core_Helper_Abstract
/**
* Request object
*
* @var Zend_Controller_Request_Http
* @var Mage_Core_Controller_Request_Http
*/
protected $_request;

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class Mage_Core_Model_App
/**
* Response object
*
* @var Zend_Controller_Response_Http
* @var Mage_Core_Controller_Response_Http
*/
protected $_response;

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ public function loadEnv(): Mage_Core_Model_Config
/**
* Reinitialize configuration
*
* @param array $options
* @param Mage_Core_Model_Config_Options|array $options
* @return $this
*/
public function reinit($options = [])
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Core/Model/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Mage_Core_Model_Cookie
/**
* Set Store object
*
* @param mixed $store
* @param bool|int|Mage_Core_Model_Store|null|string $store
* @return $this
*/
public function setStore($store)
Expand Down Expand Up @@ -199,7 +199,7 @@ public function isSecure()
*
* @param string $name The cookie name
* @param string $value The cookie value
* @param int $period Lifetime period
* @param int|bool $period Lifetime period
* @param string $path
* @param string $domain
* @param int|bool $secure
Expand Down
4 changes: 3 additions & 1 deletion app/code/core/Mage/Core/Model/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ public function getConfig()
*/
public function getUrlRewriteInstance()
{
return $this->getModel($this->getUrlRewriteClassAlias());
/** @var Mage_Core_Model_Url_Rewrite $model */
$model = $this->getModel($this->getUrlRewriteClassAlias());
return $model;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Eav/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ protected function _hydrateAttribute($attributeData)
/**
* Get entity type object by entity type code/identifier
*
* @param mixed $code
* @param Mage_Eav_Model_Entity_Type|string|int $code
* @param string|null $field
* @return Mage_Eav_Model_Entity_Type
* @throws Mage_Core_Exception
Expand Down Expand Up @@ -537,7 +537,7 @@ public function getAttributes($entityType)
/**
* Get codes of all entity type attributes
*
* @param Mage_Eav_Model_Entity_Type $entityType
* @param Mage_Eav_Model_Entity_Type|string|int $entityType
* @param Varien_Object $object
* @return array
* @throws Mage_Core_Exception
Expand Down
4 changes: 3 additions & 1 deletion app/code/core/Mage/Index/Model/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ protected function _getLockStorage()
{
if (!$this->_storage instanceof Mage_Index_Model_Lock_Storage_Interface) {
$config = Mage::getConfig()->getNode(self::STORAGE_CONFIG_PATH);
$this->_storage = Mage::getModel($config->model);
/** @var Mage_Index_Model_Lock_Storage_Interface $model */
$model = Mage::getModel($config->model);
$this->_storage = $model;
}
return $this->_storage;
}
Expand Down
4 changes: 3 additions & 1 deletion app/code/core/Mage/Install/Model/Installer/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class Mage_Install_Model_Installer_Db extends Mage_Install_Model_Installer_Abstract
{
/**
* @var resource database
* @var Mage_Install_Model_Installer_Db_Abstract|null database
*/
protected $_dbResource;

Expand Down Expand Up @@ -141,10 +141,12 @@ protected function _getCheckedData($data)
*
* @param string $model database type
* @return Mage_Install_Model_Installer_Db_Abstract
* @throws Mage_Core_Exception
*/
protected function _getDbResource($model)
{
if (!isset($this->_dbResource)) {
/** @var Mage_Install_Model_Installer_Db_Abstract $resource */
$resource = Mage::getSingleton(sprintf('install/installer_db_%s', $model));
if (!$resource) {
Mage::throwException(
Expand Down
6 changes: 4 additions & 2 deletions app/code/core/Mage/Paypal/Model/Direct.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ class Mage_Paypal_Model_Direct extends Mage_Payment_Model_Method_Cc
public function __construct($params = [])
{
$proInstance = array_shift($params);
if ($proInstance && ($proInstance instanceof Mage_Paypal_Model_Pro)) {
if ($proInstance instanceof Mage_Paypal_Model_Pro) {
$this->_pro = $proInstance;
} else {
$this->_pro = Mage::getModel($this->_proType);
/** @var Mage_Paypal_Model_Pro $model */
$model = Mage::getModel($this->_proType);
$this->_pro = $model;
}
$this->_pro->setMethod($this->_code);
}
Expand Down
6 changes: 4 additions & 2 deletions app/code/core/Mage/Paypal/Model/Express.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ class Mage_Paypal_Model_Express extends Mage_Payment_Model_Method_Abstract imple
public function __construct($params = [])
{
$proInstance = array_shift($params);
if ($proInstance && ($proInstance instanceof Mage_Paypal_Model_Pro)) {
if ($proInstance instanceof Mage_Paypal_Model_Pro) {
$this->_pro = $proInstance;
} else {
$this->_pro = Mage::getModel($this->_proType);
/** @var Mage_Paypal_Model_Pro $model */
$model = Mage::getModel($this->_proType);
$this->_pro = $model;
}
$this->_pro->setMethod($this->_code);
$this->_setApiProcessableErrors();
Expand Down
5 changes: 4 additions & 1 deletion app/code/core/Mage/Paypal/Model/Pro.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ public function setMethod($code, $storeId = null)
if ($storeId !== null) {
$params[] = $storeId;
}
$this->_config = Mage::getModel($this->_configType, $params);

/** @var Mage_Paypal_Model_Config $model */
$model = Mage::getModel($this->_configType, $params);
$this->_config = $model;
} else {
$this->_config->setMethod($code);
if ($storeId !== null) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Tax/Model/Resource/Class/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function _construct()
/**
* Add class type filter to result
*
* @param int $classTypeId
* @param string $classTypeId
* @return $this
*/
public function setClassTypeFilter($classTypeId)
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Weee/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function getProductWeeeAttributes(
/**
* Returns applied weee taxes
*
* @param Mage_Sales_Model_Quote_Item_Abstract $item
* @param Mage_Sales_Model_Quote_Item_Abstract|Varien_Object $item
* @return array
*/
public function getApplied($item)
Expand Down Expand Up @@ -608,7 +608,7 @@ public function getBaseTotalTaxAppliedForWeeeTax($item)
/**
* Get the Total tax applied for Weee
*
* @param Mage_Core_Model_Abstract $item
* @param Mage_Core_Model_Abstract|Varien_Object $item
* @return float
*/
public function getTotalRowTaxAppliedForWeeeTax($item)
Expand All @@ -625,7 +625,7 @@ public function getTotalRowTaxAppliedForWeeeTax($item)
/**
* Get the Total tax applied in base for Weee
*
* @param Mage_Core_Model_Abstract $item
* @param Mage_Core_Model_Abstract|Varien_Object $item
* @return float
*/
public function getBaseTotalRowTaxAppliedForWeeeTax($item)
Expand Down
Loading
Loading