You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To make phpstan (or PHPStorm) work properbly, you have to ...
add annotions to every method
add magic methods to class annotation
change return types in some Varien classen (Varien_ to $this)
I guess this could be merged w/o problems, but there are some other things that need to be changed ... and I don't know what will be accepted.
1. Magic methods on Varien_Object
I started to change it to setter/getter, but this would cause 1000s of changes .... no. Other idea is to add some pseudo classes that extend Varien_Object. See 088d028
2. How to deal with observers?
Since getEvent() isn't defined it could return anything ... like ->getEvent()->getProduct(). Change to getter/setter as started doen't resolve child methods ("cannot find declaration"). Useless changes ...
Idea to fix it ...
Example: autocomplete/checks for controller_action_noroute event:
/**
* Modify No Route Forward object
*
* @param Varien_Event_Observer$observer
* @return $this
*/
public function noRoute(Varien_Event_Observer $observer)
{
$observer->getEvent()->getStatus()
->setLoaded(true)
->setForwardModule('cms')
->setForwardController('index')
->setForwardAction('noRoute');
return $this;
}
we need to define a return type for observers $observer->getEvent(). So add a pseudo class that just contains the "correct" new definded return type.
/**
* Class Mage_Core_Helper_Object_Observer_Controller_Action
*
* @method Mage_Core_Helper_Object_Observer_Controller_Action_Event getEvent()
*/
class Mage_Core_Helper_Object_Observer_Controller_Action extends Varien_Event_Observer
{
}
phpstan errors that return types are diffent and signature doest fit to parent method. The parent just returns $this, so it could be solved (and make code more consistent) with returning parent method and change DOCs to @inheritDoc
4. Undefined methods for Mage_Core_Model_Abstract in resource models befor/after calls
phpstan/IDE doesn't know about child methods ... so there are 2 approches ...
"workaround": replace @param Mage_Core_Model_Abstract with Mage_Core_Model_Abstract|Mage_Some_Model_Name
change: add type checks like reverted here 51e4b6a. The object should not be anything else as the related model, not?
However, the workaround should be okay and needs less changes ...
5. Undefined methods for concrete blocks in _prepareLayout()
More an IDE improvement ... e.g. head block that is loaded in many classes, like Mage_Cms_Block_Page
$head = $this->getLayout()->getBlock('head');
if ($head) {
$head->setTitle($page->getTitle());
$head->setKeywords($page->getMetaKeywords());
$head->setDescription($page->getMetaDescription());
}
head is defined in layout XML as page/html_head, so it would be correct to check instance of Mage_Page_Block_Html_Head as it is done some line above for breadcrumbs ...
if ($breadcrumbs instanceof Mage_Page_Block_Html_Breadcrumbs) {
foreach ($breadcrumbsObject->getData('crumbs') as $breadcrumbsItem) {
$breadcrumbs->addCrumb($breadcrumbsItem['crumbName'], $breadcrumbsItem['crumbInfo']);
}
}
Changing this should break nothing and looks like unconsistent code too.
Before I continue my PRs please let me know whats accectable and whats not. :)
The text was updated successfully, but these errors were encountered:
I started to change it to setter/getter, but this would cause 1000s of changes .... no. Other idea is to add some pseudo classes that extend Varien_Object. See 088d028
Instead renaming Varien_Object it should work a @param annotation for a pseudo class eg.
/** @var OpenMageLts_Object_<path_pattern> $params */
$params = new Varien_Object();
Set @var annotation where it is used
Add classes that inherit from Varien_Object to lib/OpenMageLts/<path_pattern>
So no changes in code just some @var and helper classes for PHPStorm/PHPStan ...?
#365
To make phpstan (or PHPStorm) work properbly, you have to ...
Varien_
to$this
)I guess this could be merged w/o problems, but there are some other things that need to be changed ... and I don't know what will be accepted.
1. Magic methods on
Varien_Object
I started to change it to setter/getter, but this would cause 1000s of changes .... no. Other idea is to add some pseudo classes that extend
Varien_Object
. See 088d0282. How to deal with observers?
Since
getEvent()
isn't defined it could return anything ... like->getEvent()->getProduct()
. Change to getter/setter as started doen't resolve child methods ("cannot find declaration"). Useless changes ...Idea to fix it ...
Example: autocomplete/checks for
controller_action_noroute
event:$observer->getEvent()
. So add a pseudo class that just contains the "correct" new definded return type.noRoute()
DOC togetEvent()
should retrunVarien_Event
we have to add another pseudo class where we access the passed data ...This would cover
Mage_Core_Controller_Varien_Action::norouteAction()
Varien_Object
withMage_Core_Helper_Object_Request
Varien_Object
replacement3. Missing call to parent method
Example 088d028
phpstan errors that return types are diffent and signature doest fit to parent method. The parent just returns
$this
, so it could be solved (and make code more consistent) with returning parent method and change DOCs to@inheritDoc
4. Undefined methods for
Mage_Core_Model_Abstract
in resource models befor/after callsphpstan/IDE doesn't know about child methods ... so there are 2 approches ...
@param Mage_Core_Model_Abstract
withMage_Core_Model_Abstract|Mage_Some_Model_Name
However, the workaround should be okay and needs less changes ...
5. Undefined methods for concrete blocks in
_prepareLayout()
More an IDE improvement ... e.g. head block that is loaded in many classes, like
Mage_Cms_Block_Page
head
is defined in layout XML aspage/html_head
, so it would be correct to checkinstance of Mage_Page_Block_Html_Head
as it is done some line above for breadcrumbs ...Changing this should break nothing and looks like unconsistent code too.
Before I continue my PRs please let me know whats accectable and whats not. :)
The text was updated successfully, but these errors were encountered: