Skip to content

Commit

Permalink
fix: Solved rest of PHPStan complaints due to changed return type of …
Browse files Browse the repository at this point in the history
…Mage::getSingleton().

Added explanation to type hints as well.
  • Loading branch information
Sdfendor committed Jul 19, 2022
1 parent fc9901c commit c9d165c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
8 changes: 6 additions & 2 deletions app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,14 @@ public function initFields($fieldset, $group, $section, $fieldPrefix='', $labelP
$method = false;
if (preg_match('/^([^:]+?)::([^:]+?)$/', $factoryName, $matches)) {
array_shift($matches);
list($factoryName, $method) = array_values($matches);
[$factoryName, $method] = array_values($matches);
}

/** @var Mage_Core_Model_Abstract $sourceModel */
/**
* PHPStan can't infer type because $factoryName is dynamic. Type hint prevents '|false' return
* type case.
* @var Mage_Core_Model_Abstract $sourceModel
*/
$sourceModel = Mage::getSingleton($factoryName);
if ($sourceModel instanceof Varien_Object) {
$sourceModel->setPath($path);
Expand Down
8 changes: 6 additions & 2 deletions app/code/core/Mage/Catalog/Helper/Product/Flat.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ public function getFlag()
{
if (is_null($this->_flagObject)) {
$className = (string)Mage::getConfig()->getNode(self::XML_PATH_FLAT_FLAG);
$this->_flagObject = Mage::getSingleton($className)
->loadSelf();
/**
* PHPStan can't infer type because $className is dynamic. Type hint prevents '|false' return type case.
* @var Mage_Catalog_Model_Product_Flat_Flag $flagObjectSingleton
*/
$flagObjectSingleton = Mage::getSingleton($className);
$this->_flagObject = $flagObjectSingleton->loadSelf();
}
return $this->_flagObject;
}
Expand Down
10 changes: 8 additions & 2 deletions app/code/core/Mage/Core/Block/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ public function sortChildren($force = false)
{
$this->_sortedChildren = array_values($this->_sortedChildren); // reset indexes which might have gaps after unsetting blocks
foreach ($this->_sortInstructions as $name => $list) {
list($siblingName, $after, $exists) = $list;
[$siblingName, $after, $exists] = $list;
if ($exists && !$force) {
continue;
}
Expand Down Expand Up @@ -1304,7 +1304,13 @@ protected function _afterCacheUrl($html)
if ($this->_getApp()->useCache(self::CACHE_GROUP)) {
$this->_getApp()->setUseSessionVar(false);
Varien_Profiler::start('CACHE_URL');
$html = Mage::getSingleton($this->_getUrlModelClass())->sessionUrlVar($html);
/**
* PHPStan can't infer type because $this->_getUrlModelClass() depends on implementation. Type hint
* prevents '|false' return type case.
* @var Mage_Core_Model_Url $urlModelClass
*/
$urlModelClass = Mage::getSingleton($this->_getUrlModelClass());
$html = $urlModelClass->sessionUrlVar($html);
Varien_Profiler::stop('CACHE_URL');
}
return $html;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ class Mage_Oauth_Customer_TokenController extends Mage_Core_Controller_Front_Act
public function preDispatch()
{
parent::preDispatch();
$this->_session = Mage::getSingleton($this->_sessionName);
/**
* PHPStan can't infer type because $this_sessionName is dynamic. Type hint prevents '|false' return type case.
* Temp variable $session is therefore necessary.
* @var Mage_Customer_Model_Session $session
*/
$session = Mage::getSingleton($this->_sessionName);
$this->_session = $session;
if (!$this->_session->authenticate($this)) {
$this->setFlag('', self::FLAG_NO_DISPATCH, true);
}
Expand Down

0 comments on commit c9d165c

Please sign in to comment.