andersundsehr / phpstan-git-files
Add all git files into phpstan config automatically
Package info
github.com/andersundsehr/phpstan-git-files
pkg:composer/andersundsehr/phpstan-git-files
Requires
- php: ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0
- composer-plugin-api: ^2.1.0
- phpstan/phpstan: ^1.9 || ^2.0
Requires (Dev)
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
andersundsehr/phpstan-git-files
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.
Requirements
- 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
Installation
composer require --dev andersundsehr/phpstan-git-files
Include the extension in your phpstan.neon and remove your own paths:
includes: - vendor/andersundsehr/phpstan-git-files/extension.php parameters: level: 8
Run PHPStan from the directory that contains your phpstan.neon, usually the project root:
vendor/bin/phpstan analyse
How it works
extension.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.
Contributing
This package is developed in the monorepo andersundsehr/grumphp-config. Please open issues and pull requests there.
License
LGPL-3.0-or-later
with ♥️ from anders und sehr GmbH
If something did not work 😮
or you appreciate this Extension 🥰 let us know.
We are hiring https://www.andersundsehr.com/karriere/