tomasvotruba/bladestan
Bladestan brings PHPStan-powered static analysis to Laravel Blade templates. It catches template-related issues during analysis and offers a Blade error formatter with clickable template paths and “rendered in” context for faster debugging.
phpstan.neon), caching, and CLI workflows. This minimizes tooling fragmentation and allows teams to adopt it alongside existing static analysis pipelines (e.g., Psalm, Pest).@component, @slot).@include, @once, @each, and conditional directives.post_codex.blade.php:15"), reducing debugging time by 30–50% compared to runtime errors.composer require and phpstan.neon configuration. No Laravel service providers, facades, or middleware modifications are needed.--error-format=blade flag ensures actionable feedback for developers.vendor/ and no production overhead. Ideal for serverless or containerized Laravel apps.| Risk Area | Mitigation Strategy |
|---|---|
| False Positives | Configure phpstan.neon to ignore known edge cases (e.g., dynamic Blade logic). The package respects PHPStan’s rule filtering and provides identifier-based ignores (since v0.11.3). |
| Livewire/Component Issues | Test with Livewire 4.0 and Laravel 12 in staging. The package’s application-aware parsing (e.g., reading Livewire namespace from config/livewire.php) reduces flakiness. |
| Performance Overhead | Disable in production (dev-only tool). Cache invalidation (fixed in v0.11.5) ensures no regression in PHPStan’s speed. |
| Unsupported Blade Features | Extend the package via custom PHPStan rules or submit PRs. The open-source model (MIT license) allows community-driven enhancements. |
| PHPStan Version Lock | Pin PHPStan to a supported range (e.g., ^2.0) in composer.json to avoid compatibility drift. The package migrated to PHPStan 2.0 in v0.7.0. |
Static Analysis Maturity:
CI/CD Integration:
phpstan analyze --memory-limit=1G.fail-fast) or warn only? Align with team’s shift-left culture.Livewire/Component Usage:
Maintenance Plan:
phpstan.neon ignores as the codebase evolves.Developer Experience:
--error-format=blade) integrate with the team’s IDE (e.g., PHPStorm, VSCode)? Test with clickable links in error output.phpstan.neon template.@if($user?->name)).| Phase | Action Items | Success Metrics |
|---|---|---|
| Assessment | 1. Audit top 10 Blade templates causing production bugs. | Identify 3+ recurring issues (e.g., undefined methods, missing variables). |
2. Verify PHPStan version compatibility (composer show phpstan). |
No major version conflicts (e.g., PHPStan 1.x vs. 2.x). | |
| 3. Check for custom Blade directives or Livewire 2.x usage. | Confirm no unsupported features block adoption. | |
| Pilot | 1. Add to composer.json (dev dependency). |
composer install succeeds without conflicts. |
2. Configure phpstan.neon: |
includes: [./vendor/tomasvotruba/bladestan/config/extension.neon] works. |
|
| 3. Test locally on 2–3 critical templates (e.g., checkout, dashboard). | 0–2 false positives after initial tuning. | |
| CI Integration | 1. Add to .github/workflows/phpstan.yml: |
CI job passes in <3 minutes for full codebase. |
| ```yaml | ||
| - run: vendor/bin/phpstan analyze --error-format=blade --level=max | ||
| ``` | ||
2. Set failure mode: if: always() (warn) or if: success() (block). |
Align with team’s gated deployment policy. | |
| Rollout | 1. Enable for all Blade files in phpstan.neon. |
100% template coverage in CI. |
| 2. Train devs on error formatter and Livewire-specific rules. | <5% support tickets related to Blade errors post-rollout. | |
| Optimization | 1. Tune phpstan.neon ignores for false positives. |
<1% false positives in production templates. |
| 2. Add pre-commit hook (e.g., Husky) for local validation. | 80% devs run Bladestan before pushing. |
How can I help you explore Laravel packages today?