- How does this package help Laravel projects avoid manual `includePaths` in PHPStan config?
- It automatically scans your Git repository for all tracked `.php` files and feeds them into PHPStan, eliminating the need to manually list directories or files in your `phpstan.neon`. This ensures analysis covers exactly what’s in version control, including Laravel’s `app/`, `routes/`, and `tests/` directories.
- Will this work with Laravel 8/9 apps still using PHPStan 10.x?
- Yes, this package explicitly backports functionality to PHPStan 10.x, making it compatible with Laravel 8/9 projects. The backport addresses potential issues like `getcwd()` path resolution in CI environments, which is critical for legacy setups.
- Does this package handle Laravel-specific directories like `storage/framework/views` or `bootstrap/cache`?
- No, it includes *all* Git-tracked `.php` files by default. You’ll need to explicitly exclude Laravel-specific directories in your `phpstan.neon` using `excludePaths`, such as `- storage/framework/views/ - bootstrap/cache/`, to avoid analyzing generated or sensitive files.
- How do I install and configure this for Laravel?
- Run `composer require --dev andersundsehr/phpstan-git-files`, then include the extension in your `phpstan.neon` under `includes`. No additional configuration is needed unless you want to exclude specific paths. The package works out of the box with Laravel’s default directory structure.
- Is this package safe to use in CI/CD pipelines? Does it handle non-standard working directories?
- The backport to PHPStan 10.x includes fixes for `getcwd()` issues, improving reliability in CI environments. However, test it in your pipeline by running `pwd` and `git rev-parse --show-toplevel` to confirm path resolution matches your repo’s root, especially if you use custom working directories.
- Can I use this with PHPStan 11.x or later?
- This package only supports PHPStan 10.x. For PHPStan 11.x, check for native Git integration or wait for an updated version of this package. Upgrading to PHPStan 11.x may require additional testing to ensure compatibility with Laravel’s ecosystem.
- What if my Laravel project uses Git submodules or symlinked directories?
- The package should handle symlinked directories automatically since it relies on Git’s `ls-files`. For submodules, ensure they’re initialized (`git submodule update --init`) before running PHPStan, as the extension only scans the main repository’s tracked files. Test edge cases like sparse checkouts if applicable.
- Does this replace the need for custom Artisan commands to resolve PHPStan paths?
- Yes, if your custom commands rely on `getcwd()` or manual path resolution, you can simplify them by leveraging this package. For example, replace hardcoded paths with `base_path()` and include the extension directly in your PHPStan command, as shown in the updated Artisan example in the README.
- Are there any performance concerns for large Laravel repositories?
- The package adds minimal overhead since it only scans Git-tracked files once per analysis. Performance impact is negligible for most projects, but benchmark in your CI pipeline if you have thousands of files. Avoid excluding critical paths, as this could reduce coverage.
- What alternatives exist for automating PHPStan file inclusion in Laravel?
- Alternatives include manually configuring `includePaths` in `phpstan.neon` or using PHPStan’s `--include-extension` with third-party extensions like `phpstan/extension-installer`. However, this package is the most Git-aware solution, ensuring analysis matches your repo’s exact state without manual maintenance.