This package provides some additional features for PHPStan to make it work for Magento 2 projects. You can use this PHPStan extension for both Magento module projects and Magento application projects.
PHP: PHP 7.2 or higher
Magento: Magento 2.3.0 or higher
PHPStan: PHPStan 1.3
If you are using a Magento version that requires an older version of PHPStan (e.g. 0.12.77), you need to manually upgrade it before
installing this extension. in your composer.json Change the PHPStan version to ~1.3 and run:
composer update phpstan/phpstan --with-all-dependencies
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
If you have not already a PHPStan configuration file phpstan.neon in your project, create a new empty file next to your composer.json file.
This PHPStan extension needs to be registered with PHPStan so that PHPStan can load it properly.
The easiest way to do this is to install the phpstan/extension-installer package as follows:
composer.phar require --dev phpstan/extension-installer
Manual installation
If you don't want to use phpstan/extension-installer, include extension.neon in your project's PHPStan config:
includes:
- vendor/bitexpert/phpstan-magento/extension.neonIf you are using phpstan-magento 0.15.0 and earlier, you need to register the custom autoloader that comes with this extension by adding vendor/bitexpert/phpstan-magento/autoload.php
as a bootstrap file. If you are using phpstan-magento > 0.15.0 this step is done automatically by the extension itself.
parameters:
bootstrapFiles:
- vendor/bitexpert/phpstan-magento/autoload.phpThis PHPStan extension works for both Magento module projects and Magento application projects.
- Class generator for factory & proxy classes
- Mocked classes autoloader
- TestFramework autoloader
- Type hints
- TestFramework ObjectManager type hints
- ObjectManager type hints
- Magic method calls
- Extension attributes
- PHPStan rules
- Service contracts
- Collections should be used directly via factory
For a detailed overview, check the feature documentation here.
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.