calebdw/larastan-livewire
Larastan Livewire adds PHPStan/Larastan support for Livewire components, helping static analysis understand public properties, computed properties, actions, validation, and view data so you catch type errors and undefined members before runtime.
composer require --dev calebdw/larastan-livewire
phpstan.neon (or .dist). Because it builds on Larastan, include Larastan first, then this package:
includes:
- vendor/larastan/larastan/extension.neon
- vendor/calebdw/larastan-livewire/extension.neon
vendor/bin/phpstan analyse app/Livewire --level=5
Where to look first: the packaged extension.neon (it lists the registered services, type extensions, and rules — the fastest way to see what is actually wired up), then the src/ directory for the type extensions and rules, and tests/ for canonical usage examples. Check composer.json's require block to confirm it targets your Livewire 2 vs 3 and PHPStan major version.
First use case: run the analyser against a single component with public properties, mount(), actions, and a couple of $this->... calls. Before adding the extension you'll typically see "undefined property/method" noise on Livewire magic accessors; after including it those should resolve, confirming the install is live.
app/Livewire (and app/Http/Livewire for Livewire 2 projects) at a moderate level, then widen paths and raise the level once the baseline is clean.$this resolution). Keep Larastan's extension included.@var/@property docblocks on the component to state the intended shape — the extension will then infer $this->foo consistently in actions, mount(), and tests.$this->someComputed() returns the right type inside other methods and inside your test cases. This is the biggest day-to-day payoff: Livewire::test(MyComponent::class)->call('doThing') chains become typed.phpstan analyse --memory-limit=1G after composer install --no-progress and fails the build on error. Pair with a generated baseline only for legacy code, then shrink it.$this->…) is also surfaced through PHPStan's language server / editor plugins, so you get completion and diagnostics on Livewire internals you'd otherwise fly blind on.phpstan analyse app/Livewire/Foo.php) before opening a PR — cheaper and faster feedback than the full-app CI run.app/Livewire only, so new code is held to the stricter standard while legacy components are frozen.extension.neon before Larastan's, some services may not see the Laravel container types they depend on. Always put Larastan first.phpstan/phpstan or larastan/larastan, re-run the analyser against a known-good component before trusting results — silent inference regressions are more common than hard errors.vendor/bin/phpstan clear-result-cache after editing phpstan.neon or upgrading; stale caches produce confusing "no errors" runs.$this->anything resolve at runtime via magic methods, but PHPStan wants a declaration. Don't disable strictness to hide this — add the property or a @property docblock, otherwise you lose the type safety the extension is meant to give you.mixed at the boundary and validate before use. Don't silence PHPStan warnings about them — that's the bug class the analyser should catch.wire:model bindings, wire:click actions, and $wire calls inside .blade.php are not type-checked by this extension. If you need that coverage, look at companion tooling (e.g., Blade-specific extensions) — don't assume this package covers them.--memory-limit or split analysis into multiple paths if you hit OOM.-vvv and --debug to see which extensions ran and where a type went to mixed. If a property unexpectedly resolves to mixed, verify the component is actually discovered — a path outside the configured paths won't be analyzed at all.PHPStan\Rules\Rule implementations or DynamicMethodReturnTypeExtension services via an app-level phpstan.neon services: block. This is the clean way to teach PHPStan about project-specific base component classes or custom traits that the package can't know about.How can I help you explore Laravel packages today?