A PHPStan extension that analyses all PHP files tracked in git.
You no longer maintain paths in your phpstan.neon: new files are analysed as soon as they are added to git, and untracked or ignored files, such as vendor/ or generated code, stay out.
This extension is part of
pluswerk/grumphp-config. If you use that package, the generatedphpstan.neonalready includes it.
- PHP 8.2 or newer
- PHPStan 1.9 or newer, or PHPStan 2
- git and a shell with
xargs,ls,grepandawk shell_exec()must be allowed in PHP CLI- at least one tracked
.phpfile
composer require --dev andersundsehr/phpstan-git-filesInclude the extension in your phpstan.neon and remove your own paths:
includes:
- vendor/andersundsehr/phpstan-git-files/extension.php
parameters:
level: 8Run PHPStan from the directory that contains your phpstan.neon, usually the project root:
vendor/bin/phpstan analyseextension.php returns PHPStan configuration with these parameters:
paths: all files fromgit ls-filesbelow the current directory that end in.phpand still exist, as absolute paths.excludePaths.analyse: git-ignored files in one directory, see below.
To keep PHPStan's result cache working (see issue #3), paths must contain a directory and not only single files. The extension therefore takes the deepest directory that contains a tracked PHP file and lists that directory instead of its files. To keep ignored files in that directory out of the analysis, it adds them to excludePaths.analyse. As a side effect, untracked PHP files that are not ignored by git are analysed if they are in that one directory.
The extension runs git only once per PHP process and reuses the result.
This package is developed in the monorepo andersundsehr/grumphp-config. Please open issues and pull requests there.
LGPL-3.0-or-later
If something did not work 😮
or you appreciate this Extension 🥰 let us know.
We are hiring https://www.andersundsehr.com/karriere/