tomasvotruba/bladestan
Bladestan adds PHPStan-powered static analysis for Laravel Blade templates. Install as a dev dependency and include its extension if needed. Provides a custom “blade” error formatter showing clickable template paths and where errors are rendered.
@include($dynamicPartial)), which may trigger false positives. Mitigation: Configure PHPStan’s ignoreErrors or level settings to tune sensitivity (e.g., ignore undefinedMethod for specific classes).@php blocks with complex expressions) may not be fully analyzable. Risk is low for most use cases, but edge cases (e.g., custom Blade directives) might require manual review.--error-format=blade output. Workaround: Use the CLI or configure PHPStan’s IDE integration to parse the custom format.paths configuration.@include($variable)) vs. static? Dynamic templates may yield more false positives.@php logic that might not be fully supported?undefinedMethod) be ignored for specific classes?@endsection) be prioritized vs. PHPStan’s other rules?phpstan.neon edits.includes:
- ./vendor/tomasvotruba/bladestan/config/extension.neon
extension.neon in a project-specific config (e.g., phpstan-blade.neon).config/view.paths, avoiding hardcoded assumptions.config/livewire.php) and Symfony mail templates (e.g., resources/views/emails/*.blade.php).Response::view() and View::make() calls, including data passed via with(), withShare(), etc.vendor/bin/phpstan analyze --memory-limit=1G --parallel
@endsection) using a trial run:
composer require --dev tomasvotruba/bladestan
vendor/bin/phpstan analyze --error-format=blade --level=5
level or ignoreErrors as needed.composer.json under require-dev:
"require-dev": {
"tomasvotruba/bladestan": "^0.11"
}
- name: Blade Template Analysis
run: vendor/bin/phpstan analyze --error-format=blade --level=5
make or npm script for local analysis:
"scripts": {
"test:bladestan": "phpstan analyze --error-format=blade"
}
post_codex.blade.php:15 links).resources/views/*.blade.php).resources/views/emails/*.blade.php).resources/views/livewire/*.blade.php).@include($partial)).paths or excludePaths:
paths:
- app
- config
- routes
- tests
excludePaths:
- vendor
- storage/framework/views
level settings to control strictness (e.g., level: 5 for all rules, or level: 3 for select files).^0.11) to avoid surprises.How can I help you explore Laravel packages today?