Fichier de configuration PHPStan typique pour un projet Symfony
Publié le 11/11/2020 • Actualisé le 20/11/2020
Voici un fichier de configuration PHPStan typique pour un projet Symfony. J'ai ajouté des liens vers la documentation afin de voir la signification de chaque paramètre. Il y a quelques plugins à installer. Celui relatif à Symfony est essentiel puisqu'il permet à PHPStan d'avoir accès et de pouvoir inspecter le conteneur de dépendances. Les autres ajoutent des règles supplémentaires. Bien sûr, vous êtes libres de les installer ou pas. Si vous commencer à utiliser PHPStan sur un ancien projet, il va surement détecter de nombreux problèmes. Dans ce cas, mon conseil est de commencer au niveau 0 puis de passer au suivant une fois que toutes les erreurs ont été corrigées. Prenez ça comme un jeu ! 😀
# configuration/phpstan.neon
includes:
# require phpstan/extension-installer to avoid including these lines PHPStan 1.x compat
#- vendor/ekino/phpstan-banned-code/extension.neon # https://github.com/ekino/phpstan-banned-code ✅
#- vendor/phpstan/phpstan-symfony/extension.neon # https://github.com/phpstan/phpstan-symfony ✅
#- vendor/phpstan/phpstan-deprecation-rules/rules.neon # https://github.com/phpstan/phpstan-deprecation-rules ✅
#- vendor/phpstan/phpstan-strict-rules/rules.neon # https://github.com/phpstan/phpstan-strict-rules ✅
#- vendor/phpstan/phpstan/phpstan-doctrine # https://github.com/phpstan/phpstan-doctrine ✅
#- phar://phpstan.phar/conf/bleedingEdge.neon # https://phpstan.org/blog/what-is-bleeding-edge
# These are custom rules, check-out: https://www.strangebuzz.com/en/blog/creating-custom-phpstan-rules-for-your-symfony-project
rules:
- App\PHPStan\ControllerIsFinalRule
- App\PHPStan\ControllerExtendsSymfonyRule
#- App\PHPStan\NoNewinControllerRule
parameters:
# https://phpstan.org/config-reference#rule-level
level: 9 # Pinned to 9; max is level 10 as of PHPStan 2.0
# https://phpstan.org/config-reference#analysed-files
# Note that I have put my configuraiton file in the "./configuration" directory
# if you have yours at the root of your project remove the "../"
paths:
- ../config
- ../src
- ../tests
- ../public
excludePaths:
- ../config/reference.php # generated
- ../src/Controller/Snippet/Snippet303Trait.php
# https://github.com/phpstan/phpstan-symfony#configuration
# Specific configuration for the Symfony plugin
symfony:
# I use the prod env because I have false positive regarding the tests which
# are executed in the test environment.
containerXmlPath: ../var/cache/prod/App_KernelProdDebugContainer.xml
# https://github.com/phpstan/phpstan-doctrine — a nullable property backed by a
# non-nullable column is a normal pre-persist pattern in this project.
doctrine:
allowNullablePropertyForRequiredField: true
# Nothing ignored! (almost!) 🎉
ignoreErrors:
# I don't use the Symfony PHPUnit bridge in this project, but if you do, you
# probably will have to add the following bootstrap file:
#bootstrapFiles:
#- %rootDir%/../../../vendor/bin/.phpunit/phpunit/vendor/autoload.php
Plus sur Stackoverflow Lire la doc Plus sur le web Snippet aléatoire
A vous de jouer !
Ces articles vous ont été utiles ? Vous pouvez m'aider à votre tour de plusieurs manières : (cliquez sur le lien "reply" dans à droite pour me contacter )
- Me remonter des erreurs ou typos.
- Me remonter des choses qui pourraient être améliorées.
- Aimez et repostez !
- Suivez moi sur Bluesky 🦋
- Inscrivez-vous au flux RSS.
- Cliquez sur les boutons Plus sur Stackoverflow pour me faire gagner des badges "annonceur" 🏅.
Merci et à très bientôt sur Strangebuzz ! 😉