Skip to content

Commit

Permalink
Some phpstan fixes (#4283)
Browse files Browse the repository at this point in the history
* fixes [wip]

* fixes

* fixes
  • Loading branch information
sreichel authored Oct 17, 2024
1 parent aa10034 commit 01ed8fe
Show file tree
Hide file tree
Showing 31 changed files with 125 additions and 757 deletions.
703 changes: 19 additions & 684 deletions .phpstan.dist.baseline.neon

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct()
}

/**
* Retirve currently edited product model
* Retrieve currently edited product model
*
* @return Mage_Catalog_Model_Product
*/
Expand All @@ -54,7 +54,7 @@ protected function _getProduct()
/**
* Add filter
*
* @param object $column
* @param Mage_Adminhtml_Block_Widget_Grid_Column $column
* @return $this
*/
protected function _addColumnFilterToCollection($column)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct()
}

/**
* Retirve currently edited product model
* Retrieve currently edited product model
*
* @return Mage_Catalog_Model_Product
*/
Expand All @@ -54,7 +54,7 @@ protected function _getProduct()
/**
* Add filter
*
* @param object $column
* @param Mage_Adminhtml_Block_Widget_Grid_Column $column
* @return $this
*/
protected function _addColumnFilterToCollection($column)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct()
}

/**
* Retirve currently edited product model
* Retrieve currently edited product model
*
* @return Mage_Catalog_Model_Product
*/
Expand All @@ -54,7 +54,7 @@ protected function _getProduct()
/**
* Add filter
*
* @param object $column
* @param Mage_Adminhtml_Block_Widget_Grid_Column $column
* @return $this
*/
protected function _addColumnFilterToCollection($column)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function _prepareForm()
'required' => true,
'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true),
]);
$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
$renderer = $this->getStoreSwitcherRenderer();
$field->setRenderer($renderer);
} else {
$fieldset->addField('store_id', 'hidden', [
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Cms/Block/Edit/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function _prepareForm()
'required' => true,
'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true),
]);
$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
$renderer = $this->getStoreSwitcherRenderer();
$field->setRenderer($renderer);
} else {
$fieldset->addField('store_id', 'hidden', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function _prepareForm()
'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true),
'disabled' => $isElementDisabled,
]);
$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
$renderer = $this->getStoreSwitcherRenderer();
$field->setRenderer($renderer);
} else {
$fieldset->addField('store_id', 'hidden', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function(v, elem){
);
// @codingStandardsIgnoreEnd
}
$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
$renderer = $this->getStoreSwitcherRenderer();
$form->getElement('website_id')->setRenderer($renderer);

$customerStoreId = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected function _prepareForm()
'required' => true,
'values' => Mage::getSingleton('adminhtml/system_store')->getWebsiteValuesForForm()
]);
$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
$renderer = $this->getStoreSwitcherRenderer();
$field->setRenderer($renderer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected function _prepareForm()
'required' => true,
'values' => Mage::getSingleton('adminhtml/system_store')->getWebsiteValuesForForm()
]);
$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
$renderer = $this->getStoreSwitcherRenderer();
$field->setRenderer($renderer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function _prepareForm()
'name' => 'stores[]',
'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm()
]);
$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
$renderer = $this->getStoreSwitcherRenderer();
$field->setRenderer($renderer);

$fieldset->addField('position', 'text', [
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Review/Add/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function _prepareForm()
'name' => 'select_stores[]',
'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(),
]);
$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
$renderer = $this->getStoreSwitcherRenderer();
$field->setRenderer($renderer);
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Review/Edit/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function _prepareForm()
'name' => 'stores[]',
'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(),
]);
$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
$renderer = $this->getStoreSwitcherRenderer();
$field->setRenderer($renderer);
$review->setSelectStores($review->getStores());
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Adminhtml/Block/Sitemap/Edit/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function _prepareForm()
'value' => $model->getStoreId(),
'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(),
]);
$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
$renderer = $this->getStoreSwitcherRenderer();
$field->setRenderer($renderer);
} else {
$fieldset->addField('store_id', 'hidden', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function _prepareForm()
'name' => 'store_id',
'required' => true,
]);
$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
$renderer = $this->getStoreSwitcherRenderer();
$field->setRenderer($renderer);
} else {
$fieldset->addField('store_id', 'hidden', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected function _prepareForm()
'disabled' => true,
'value' => $formValues['store_id'],
]);
$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
$renderer = $this->getStoreSwitcherRenderer();
$element->setRenderer($renderer);
if ($noStoreError) {
$element->setAfterElementHtml($noStoreError);
Expand Down
8 changes: 8 additions & 0 deletions app/code/core/Mage/Adminhtml/Block/Widget/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,16 @@ protected function _getAdditionalElementTypes()
* @param Varien_Data_Form_Element_Abstract $element
* @return string
*/
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
protected function _getAdditionalElementHtml($element)
{
return '';
}

protected function getStoreSwitcherRenderer(): Mage_Adminhtml_Block_Store_Switcher_Form_Renderer_Fieldset_Element
{
/** @var Mage_Adminhtml_Block_Store_Switcher_Form_Renderer_Fieldset_Element $renderer */
$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
return $renderer;
}
}
6 changes: 3 additions & 3 deletions app/code/core/Mage/Adminhtml/Block/Widget/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Mage_Adminhtml_Block_Widget_Grid extends Mage_Adminhtml_Block_Widget
/**
* Collection object
*
* @var Mage_Core_Model_Resource_Db_Collection_Abstract|null
* @var Mage_Core_Model_Resource_Db_Collection_Abstract|Varien_Data_Collection_Db|null
*/
protected $_collection = null;

Expand Down Expand Up @@ -306,7 +306,7 @@ public function getMainButtonsHtml()
/**
* set collection object
*
* @param Mage_Core_Model_Resource_Db_Collection_Abstract $collection
* @param Mage_Core_Model_Resource_Db_Collection_Abstract|Varien_Data_Collection_Db $collection
*/
public function setCollection($collection)
{
Expand All @@ -316,7 +316,7 @@ public function setCollection($collection)
/**
* get collection object
*
* @return Mage_Core_Model_Resource_Db_Collection_Abstract
* @return Mage_Core_Model_Resource_Db_Collection_Abstract|Varien_Data_Collection_Db
*/
public function getCollection()
{
Expand Down
1 change: 1 addition & 0 deletions app/code/core/Mage/Adminhtml/Model/Giftmessage/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public function importAllowQuoteItemsFromProducts($products)
foreach ($products as $productId => $data) {
$product = Mage::getModel('catalog/product')
->setStore($this->_getSession()->getStore())
// phpcs:ignore Ecg.Performance.Loop.ModelLSD
->load($productId);
$item = $this->_getQuote()->getItemByProduct($product);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ public function getSelectionTitlePrice($_selection, $includeContainer = true)
/**
* Set JS validation container for element
*
* @param int $elementId
* @param int $containerId
* @param string $elementId
* @param string $containerId
* @return string
*/
public function setValidationContainer($elementId, $containerId)
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ public function getLinkInstance()
* Retrieve product id by sku
*
* @param string $sku
* @return int
* @return string
*/
public function getIdBySku($sku)
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Product/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function addValue(Mage_Catalog_Model_Product_Option_Value $value)
/**
* Get value by given id
*
* @param int $valueId
* @param int|string $valueId
* @return Mage_Catalog_Model_Product_Option_Value
*/
public function getValueById($valueId)
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Product/Option/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function _construct()
}

/**
* @param string $value
* @param array $value
* @return $this
*/
public function addValue($value)
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Model/Resource/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ protected function _setAttributeValue($object, $valueRow)
/**
* Insert or Update attribute data
*
* @param Mage_Catalog_Model_Abstract $object
* @param Mage_Catalog_Model_Abstract|Varien_Object $object
* @param Mage_Eav_Model_Entity_Attribute_Abstract|Mage_Catalog_Model_Resource_Eav_Attribute $attribute
* @param mixed $value
* @return Mage_Catalog_Model_Resource_Abstract
Expand Down
14 changes: 8 additions & 6 deletions app/code/core/Mage/Catalog/Model/Resource/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ public function getProductsPosition($category)
}

/**
* Get chlden categories count
* Get children categories count
*
* @param int $categoryId
* @return int
* @return string
*/
public function getChildrenCount($categoryId)
{
Expand All @@ -395,7 +395,7 @@ public function getChildrenCount($categoryId)
* Check if category id exist
*
* @param int $entityId
* @return bool
* @return string
*/
public function checkId($entityId)
{
Expand Down Expand Up @@ -430,7 +430,7 @@ public function verifyIds(array $ids)
*
* @param Mage_Catalog_Model_Category $category
* @param bool $isActiveFlag
* @return int
* @return string
*/
public function getChildrenAmount($category, $isActiveFlag = true)
{
Expand Down Expand Up @@ -458,6 +458,7 @@ public function getChildrenAmount($category, $isActiveFlag = true)
'c.attribute_id = :attribute_id AND c.store_id = :store_id AND c.entity_id = m.entity_id',
[]
)
// phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql
->where('m.path LIKE :c_path')
->where($checkSql . ' = :active_flag');

Expand Down Expand Up @@ -597,6 +598,7 @@ public function getParentDesignCategory($category)
->addFieldToFilter('level', ['neq' => 0])
->setOrder('level', 'DESC')
->load();
// phpcs:ignore Ecg.Performance.GetFirstItem.Found
return $collection->getFirstItem();
}

Expand Down Expand Up @@ -793,7 +795,7 @@ public function changeParent(
Mage_Catalog_Model_Category $newParent,
$afterCategoryId = null
) {
$childrenCount = $this->getChildrenCount($category->getId()) + 1;
$childrenCount = (int)$this->getChildrenCount($category->getId()) + 1;
$table = $this->getEntityTable();
$adapter = $this->_getWriteAdapter();
$levelFiled = $adapter->quoteIdentifier('level');
Expand Down Expand Up @@ -909,7 +911,7 @@ protected function _processPositions($category, $newParent, $afterCategoryId)
->where('parent_id = :parent_id');
$position = $adapter->fetchOne($select, ['parent_id' => $newParent->getId()]);
}
$position += 1;
++$position;

return $position;
}
Expand Down
Loading

0 comments on commit 01ed8fe

Please sign in to comment.