This PHPStan extension includes a class generator and autoloader for factory & proxy classes similar to what Magento does. When running PHPStan in the context of a Magento application this is not needed if you point PHPStan also to the generated files folder. When running Magento in the context of a stand-alone module the autoloader helps PHPStan to properly resolve the factory & proxy classes.
This PHPStan extension provides an autoloader for "mocked" classes. These are classes that replace the Magento-specific implementations to fix problems with type hints or missing methods in interfaces and such. The autoloader will check if a class, interface, or trait exists locally in the extension's folder of mocks. If so, it will load the local version instead of the one being shipped by Magento. Once those problems are fixed in Magento, those mocked files can be removed again.
This PHPStan extension provides an autoloader for Magento\TestFramework
classes to let you run PHPStan also against your test classes.
A type extension is provided for Magento\Framework\TestFramework\Unit\Helper\ObjectManager
method calls to return the correct return type.
Additionally, a PHPStan rule checks that only Magento\Framework\Data\Collection
sub classes can be passed to
Magento\Framework\TestFramework\Unit\Helper\ObjectManager::getCollectionMock()
.
A type extension is provided so that Magento\Framework\App\ObjectManager
method calls do return the correct return type.
For some classes like Magento\Framework\DataObject
or Magento\Framework\Session\SessionManager
PHPStan logic is provided
to be able to let the magic method calls return proper types.
This PHPStan extension supports extension attributes by parsing the extension_attributes.xml
files.
By default, all extension_attributes.xml
found recursively in the current working directory will be taken into account.
Current working directory means the directory in which your phpstan.neon
file resides. If you need to change this behavior,
you can define a custom path by pointing the magentoRoot
parameter to a different directory.
To disable this rule add the following code to your phpstan.neon
configuration file:
parameters:
magento:
magentoRoot: /tmp/my/other/dir
Currently, all Magento modules found in your project are taken into account. Disabled modules are not yet ignored!
The following rules are available to run checks against your codebase, e.g. if your implementation adheres to the service contracts specification. Each of the rules can be disabled if needed.
Since Magento framework version 100.1.0 entities must not be responsible for their own loading, service contracts should be used to persist entities.
To disable this rule add the following code to your phpstan.neon
configuration file:
parameters:
magento:
checkServiceContracts: false
Since Magento framework version 100.1.0 it is no longer recommended to use \Magento\Framework\Model\AbtractModel::getResource()
for retrieving the model resource. Use service contracts instead.
To disable this rule add the following code to your phpstan.neon
configuration file:
parameters:
magento:
checkResourceModelsUsedDirectly: false
Since Magento framework version 101.0.0 Collections should be used directly via factory instead of calling
\Magento\Framework\Model\AbstractModel::getCollection()
directly.
To disable this rule add the following code to your phpstan.neon
configuration file:
parameters:
magento:
checkCollectionViaFactory: false
As the ExtDN folks have put it: 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.
To disable this rule add the following code to your phpstan.neon
configuration file:
parameters:
extdn:
setTemplateDisallowedForBlockClasses: false