tomasvotruba/phpstan-bodyscan
PHPStan Bodyscan is a PHPStan extension that scans PHP method bodies for issues and surfaces them during static analysis. It helps catch body-level code problems early and fits easily into an existing PHPStan setup.
composer require --dev tomasvotruba/phpstan-bodyscan
larastan/larastan plus a phpstan.neon/phpstan.neon.dist that includes app/, routes/, and any custom source directories.vendor/bin/phpstan-bodyscan --help
vendor/bin/phpstan-bodyscan app
Then widen the scope once you know how long it takes and how noisy the report is.The first practical use case is legacy triage: run the scan over one Laravel namespace, use the report to pick the next class or module to refactor, then re-run after the change to confirm progress. v0.2.0 is the first release worth using for CI because it adds --json output and raises the default memory limit for large projects.
"scripts": {
"scan": "phpstan-bodyscan app",
"scan:json": "phpstan-bodyscan app --json > build/bodyscan.json"
}
vendor/bin/phpstan-bodyscan app --json > build/bodyscan.json
Upload build/bodyscan.json from GitHub Actions/GitLab CI and compare counts or top offenders between branches.vendor/bin/phpstan-bodyscan app/Domain/Billing
vendor/bin/phpstan-bodyscan app/Domain/Orders
This keeps memory bounded and gives teams ownership of their own reports.vendor/bin/phpstan-bodyscan app --json > build/before.json
# refactor
vendor/bin/phpstan-bodyscan app --json > build/after.json
Use jq or a small script to compare totals and per-file counts.vendor/, storage/, bootstrap/cache/, public/build/, and any generated IDE helper files. Include only paths you actually maintain.0.x package. Pin it (^0.2) and read the changelog before upgrading; CLI flags and JSON shape can change.--json is intended for machine consumption. Redirect stderr separately so progress/warning text does not corrupt the JSON:
vendor/bin/phpstan-bodyscan app --json > build/bodyscan.json 2> build/bodyscan.err
Validate with jq empty build/bodyscan.json in CI before parsing.php -d memory_limit=2G vendor/bin/phpstan-bodyscan app
If memory is still an issue, split the scan by namespace.larastan/larastan before trusting the scan output.composer dump-autoload after adding new namespaces or changing autoload config; stale autoloading can make the report incomplete.require-dev and CI only.includes, excludePaths, analysis level, and custom rules all shape what the body scan reports. Use scoped phpstan.neon files when different Laravel modules need different rules.How can I help you explore Laravel packages today?