Fichier de configuration PHPStan typique pour un projet Symfony
Publié le 11/11/2020 • Mis à jour 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 inlcuding these lines
#- 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
parameters:
# https://phpstan.org/config-reference#rule-level
level: max
# 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
# https://github.com/phpstan/phpstan-symfony#configuration
# Specific configuration for the Sumfony plugin
symfony:
container_xml_path: ../var/cache/dev/App_KernelDevDebugContainer.xml
# https://phpstan.org/config-reference#vague-typehints
checkMissingIterableValueType: true
checkGenericClassInNonGenericObjectType: true # this parameter is activated at level 6
# It's a special "dev" project, I have to ignore the following warnings because
# the use of this functions is intended.
# @see https://phpstan.org/user-guide/ignoring-errors
ignoreErrors:
- '#Should not use node with type "Expr_Exit", please change the code.#' # warnings for "die()"
- '#Should not use node with type "Stmt_Echo", please change the code.#' # warnings for "echo()"
- '#Should not use function "print_r", please change the code.#' # warnings for "print_r()"
- '#Should not use function "var_dump", please change the code.#' # warnings for "var_dump()"
- '#Should not use function "phpinfo", please change the code.#' # warnings for "phpinfo()"
- '#Service "http_client" is not registered in the container.#' # Probably a Symfony plugin bug
- '#Variable method call on#' # Strict rule I don't want to fix for now !
# 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