andersundsehr/phpstan-git-files
PHPStan extension that automatically feeds PHPStan all tracked .php files from your Git repository, so analysis always matches what’s in version control. Install via Composer and include the provided extension.neon/extension.php in your PHPStan config.
composer require --dev andersundsehr/phpstan-git-files
phpstan.neon config:
includes:
- vendor/andersundsehr/phpstan-git-files/extension.php
.php files are included:
./vendor/bin/phpstan analyse
Problem: You have a Laravel project with PHP files scattered across app/, src/, and tests/ directories, and manually maintaining includePaths in phpstan.neon is tedious.
Solution: Use phpstan-git-files to automatically include all Git-tracked .php files, reducing config drift and ensuring consistent coverage.
Daily Development:
.php files to Git (git add).git add app/Services/NewService.php
./vendor/bin/phpstan analyse # NewService.php is now checked
CI/CD Pipeline:
- name: Run PHPStan
run: ./vendor/bin/phpstan analyse
Hybrid Configuration:
includes:
- vendor/andersundsehr/phpstan-git-files/extension.php
- app/Providers/
- src/Contracts/
Artisan Command Wrapper:
// app/Console/Commands/RunPHPStan.php
public function handle()
{
$this->call('phpstan:analyse', [
'--config' => base_path('phpstan.neon'),
'--include' => base_path('vendor/andersundsehr/phpstan-git-files/extension.php'),
]);
}
Pint/CS Fixer Integration:
# .github/workflows/ci.yml
- run: ./vendor/bin/pint
- run: ./vendor/bin/phpstan analyse
Monorepo Handling:
.gitignore to scope analysis to Laravel-specific files:
excludePaths:
- vendor/
- node_modules/
- storage/
Path Resolution Issues:
getcwd() (fixed in v10.2.7), which may not match the repo root in CI/CD or multi-repo setups.getcwd() aligns with the repo root. Debug with:
echo $(getcwd)
git rev-parse --show-toplevel
Untracked Files:
vendor/, generated code) are excluded.includePaths:
includePaths:
- vendor/autoload.php
Performance Overhead:
--parallel flag:
./vendor/bin/phpstan analyse --parallel
Git-Specific Quirks:
Verify Included Files:
./vendor/bin/phpstan analyse --debug
Check Git Tracking:
git check-ignore -v path/to/file.php
Fallback Config:
includes:
- vendor/andersundsehr/phpstan-git-files/extension.php
- app/ # Fallback for critical paths
Custom Exclusions:
excludePaths to filter files:
excludePaths:
- tests/
- storage/logs/
Post-Install Hooks:
# .git/hooks/post-commit
./vendor/bin/phpstan analyse --no-progress-bar
CI/CD Validation:
- name: Check PHPStan Coverage
run: |
git ls-files "*.php" | while read file; do
if ! ./vendor/bin/phpstan analyse --paths="$file" --no-progress-bar; then
exit 1
fi
done
How can I help you explore Laravel packages today?