bitexpert / phpstan-magento
PHPStan Magento Extension
Installs: 1 522 371
Dependents: 63
Suggesters: 0
Security: 0
Stars: 134
Watchers: 10
Forks: 25
Open Issues: 6
Type:phpstan-extension
Requires
- php: ^7.2.0 || ^8.1.0
- ext-dom: *
- laminas/laminas-code: ~3.3.0 || ~3.4.1 || ~3.5.1 || ^4.5 || ^4.10
- phpstan/phpstan: ~1.12.0
- symfony/finder: ^3.0 || ^4.0 || ^5.0 || ^6.0
Requires (Dev)
- captainhook/captainhook: ^5.10.9
- captainhook/plugin-composer: ^5.3.3
- league/commonmark: ^2.3.1
- madewithlove/license-checker: ^0.10.0 || ^1.4
- magento/framework: >=102.0.0
- mikey179/vfsstream: ^1.6.10
- nette/neon: ^3.3.3
- nikic/php-parser: ^4.13.2
- phpstan/extension-installer: ^1.1.0
- phpstan/phpstan-phpunit: ^1.1.1
- phpstan/phpstan-strict-rules: ^1.2.3
- phpunit/phpunit: ^9.5.20
- squizlabs/php_codesniffer: ^3.6.2
Conflicts
- magento/framework: <102.0.0
- dev-master
- v0.32.0
- v0.31.0
- v0.30.1
- v0.30.0
- v0.29.0
- v0.28.0
- v0.27.0
- v0.26.0
- v0.25.0
- v0.24.0
- v0.23.1
- v0.23.0
- v0.22.0
- v0.21.0
- v0.20.0
- v0.19.0
- v0.18.0
- v0.17.0
- v0.16.0
- v0.15.0
- v0.14.0
- v0.13.0
- v0.12.0
- v0.11.0
- v0.10.0
- v0.9.0
- v0.8.0
- v0.7.0
- v0.6.0
- v0.5.0
- v0.4.1
- v0.4.0
- v0.3.0
- v0.2.0
- v0.1.1
- v0.1.0
- dev-dependabot/composer/symfony/finder-tw-7.1.6
- dev-dependabot/composer/nikic/php-parser-tw-5.3.1
- dev-release/r0.32.0
- dev-release/r0.31.0
- dev-release/r0.30.0
- dev-release/r0.29.0
- dev-release/r0.28.0
- dev-release/r0.27.0
- dev-release/r0.26.0
- dev-release/r0.25.0
- dev-release/r0.24.0
- dev-release/r0.23.0
- dev-release/r0.22.0
- dev-release/r0.21.0
- dev-release/r0.20.0
- dev-release/r0.19.0
- dev-release/r0.18.0
- dev-release/r0.17.0
- dev-release/r0.16.0
- dev-release/r0.15.0
- dev-release/r0.14.0
- dev-release/r0.13.0
- dev-release/r0.12.0
- dev-release/r0.11.0
- dev-release/r0.10.0
- dev-release/r0.9.0
- dev-release/r0.8.0
- dev-release/r0.7.0
- dev-release/r0.6.0
- dev-release/r0.5.0
- dev-release/r0.4.0
- dev-release/r0.3.0
- dev-release/r0.2.0
- dev-release/r0.1.0
This package is auto-updated.
Last update: 2024-11-01 15:14:41 UTC
README
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.
Requirements
PHP: PHP 7.2 or higher
Magento: Magento 2.3.0 or higher
PHPStan: PHPStan 1.12
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.12
and run:
composer update phpstan/phpstan --with-all-dependencies
This PHPStan extension needs to be registered with PHPStan so that the extension gets loaded properly. The easiest way to do this is
to install the phpstan/extension-installer
package as follows:
composer.phar require --dev phpstan/extension-installer
Composer Allow-Plugins configuration
If you're using Composer >= 2.2.0 you have to allow the execution of composer plugins (see allow-plugins section) as follows:
- Installing phpstan/extension-installer (1.1.0): Extracting archive
phpstan/extension-installer contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "phpstan/extension-installer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] y
Installation
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
Want a full walk-through of the installation & configuration process? Read the blog post at M.academy about Static Analysis in Magento with PHPStan.
PHPStan configuration
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.
See here what options PHPStan allows you to configure.
Feature overview
This 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
- Resource Models should be used directly
- Collections should be used directly via factory
- Do not use setTemplate in Block classes
For a detailed overview, check the feature documentation here.
Contribute
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.
Want To Contribute?
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.
License
PHPStan Magento Extension is released under the MIT License.