diff --git a/composer.json b/composer.json index 769642299..c346aa009 100644 --- a/composer.json +++ b/composer.json @@ -63,6 +63,11 @@ "extra": { "branch-alias": { "dev-main": "2.3-dev" + }, + "phpstan": { + "includes": [ + "phpstan/rules.neon" + ] } }, "autoload": { diff --git a/doc/articles/plugins.md b/doc/articles/plugins.md index bcbbe2cad..e26d16385 100644 --- a/doc/articles/plugins.md +++ b/doc/articles/plugins.md @@ -339,6 +339,25 @@ depend on other packages can function correctly, a runtime autoloader is created a plugin is loaded. That autoloader is only configured to load with the plugin dependencies, so you may not have access to all the packages which are installed. +## Static Analysis support + +As of Composer 2.3.7 we ship a `phpstan/rules.neon` PHPStan config file, which provides additional error checking when working on Composer plugins. + +### Usage with [PHPStan Extension Installer][13] + +The necessary configuration files are automatically loaded, in case your plugin projects declares a dependency to `phpstan/extension-installer`. + +### Alternative manual installation + +To make use of it, your Composer plugin project needs a [PHPStan config file][12], which includes the `phpstan/rules.neon` file: + +``` +includes: + - vendor/composer/composer/phpstan/rules.neon + +// your remaining config.. +``` + [1]: ../04-schema.md#type [2]: ../04-schema.md#extra [3]: https://github.com/composer/composer/blob/main/src/Composer/Plugin/PluginInterface.php @@ -350,3 +369,5 @@ so you may not have access to all the packages which are installed. [9]: https://github.com/composer/composer/blob/main/src/Composer/Plugin/Capability/CommandProvider.php [10]: https://symfony.com/doc/current/components/console.html [11]: https://github.com/composer/composer/blob/main/src/Composer/Util/SyncHelper.php +[12]: https://phpstan.org/config-reference#multiple-files +[13]: https://github.com/phpstan/extension-installer#usage