The latest release of our PHPStan extension for Magento adds two more rules to help you improve your code base:
- Resource models should be used directly: This rule detects and reports calls of
\Magento\Framework\Model\AbtractModel::getResource(). The method is deprecated for a while now in favor of service contracts. In general, instead of accessing the resource model via the
getResource()method, inject it via Dependency injection.
- Do not use
setTemplate()in Block classes. Kudos to the ExtDN folks for this rule. Setters are deprecated in Block classes because constructor arguments should be preferred instead. Any call to
$this->setTemplate()after calling upon the parent constructor would undo the configuration via XML layout.
If you disagree with these rules, you can ignore the specific errors or disable both rules globally.
Enjoy the latest release! If you run into problems, open an issue on GitHub.