PHPStan Magento Extension
This package is auto-updated.
Last update: 2023-09-07 22:43:37 UTC
This package provides some additional features for PHPStan to make it work for Magento 2 projects.
The preferred way of installing
bitexpert/phpstan-magento is through Composer.
You can add
bitexpert/phpstan-magento as a dev dependency, as follows:
composer.phar require --dev bitexpert/phpstan-magento
Include extension.neon in your project's PHPStan config:
includes: - vendor/bitexpert/phpstan-magento/extension.neon
- The extension adds an class generator for factory & proxy classes similar as Magento does it. When running PHPStan in context of a Magento application this is not needed if you point PHPStan also the the generated files folder. When running Magento in a context of a module, this is required so that PHPStan get's the full picture of all classes needed.
- The extension adds 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. If so, it will load the local version instead of the one being shipped by Magento. Once those problems are fixed in Magento, those mocks can be removed again.
- A type extension was added so that
ObjectManagercalls return the correct return type.
- For some classes like the
SessionManagerlogic was added to be able to support magic method calls.
Below is a list of known issues when using this extension:
This is because the PHPStan shim is included as a phar archive and does therefore not support overriding certain methods in it's namespace. The current known fix for this is to manually load the autoloader that comes with this extension.
Create a file in your project (for example
phpstan.php) with the following content:
Include this to the
autoload_files-section of your
parameters: autoload_files: - phpstan.php
Please feel free to fork and extend existing or add new features and send a pull request with your changes! To establish a consistent code quality, please provide unit tests for all your changes and adapt the documentation.
If you feel that you have something to share, then we’d love to have you. Check out the contributing guide to find out how, as well as what we expect from you.
PHPStan Magento Extension is released under the MIT License.