Download the PHP package happenv-com/filament-phpstan-macros without Composer
On this page you can find all versions of the php package happenv-com/filament-phpstan-macros. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download happenv-com/filament-phpstan-macros
More information about happenv-com/filament-phpstan-macros
Files in happenv-com/filament-phpstan-macros
Package filament-phpstan-macros
Short Description PHPStan and Larastan understand macros registered on Filament components.
License MIT
Homepage https://github.com/happenv-com/filament-phpstan-macros
Informations about the package filament-phpstan-macros
Filament PHPStan Macros
A PHPStan extension that makes PHPStan and Larastan understand macros registered on Filament components — TextInput, TextColumn, TextEntry, Grid, Action and everything else built on Filament's Macroable.
Filament ships its own macro trait, Filament\Support\Concerns\Macroable, instead of Laravel's Illuminate\Support\Traits\Macroable. Larastan only knows Laravel's trait, so every Filament macro call is an "undefined method" — and, as shown below, ignoring that error switches off analysis of everything chained after the macro.
Why it matters: everything after the macro goes dark
Without this package PHPStan reports every macro call as Call to an undefined method. The usual fix is an ignoreErrors entry — and that hides far more than the macro: the macro's result is unknown, so every method chained after it is no longer checked at all.
| Analysis (level 8) | Reported |
|---|---|
without this package, macro error in ignoreErrors |
nothing — both bugs pass |
| with this package | Parameter $copyMessage of method TextInput::copyable() expects Closure\|string\|null, 42 given.Call to an undefined method TextInput::maxLenght(). |
At level 9 and above the ignored macro only turns into Cannot call method copyable() on mixed for every following call — noise that tends to get ignored as well, with the same result. With this package the macro is a typed method, so the whole chain is analysed like any other Filament code.
Key features
- The code after a macro is checked again. No more
ignoreErrorsfor macros — which silently switched off analysis of everything chained after them. - Macros become real methods for PHPStan. Parameters and return type are read from the registered closure, so a wrong argument or a misused result is reported like for any native method.
- Fluent chains keep their type. A macro typed to return one of the caller's ancestors (e.g.
Fieldwhen called onTextInput) returnsstatic, so subclass-only methods after it are still known. - Filament's own lookup rules. A macro registered on the class itself wins over one registered on a parent, exactly as Filament resolves it at runtime.
- Any callable. Closures, invokable objects and array callables registered with
macro()ormixin()are all understood. - Zero configuration. With
phpstan/extension-installerthe extension registers itself; no Filament dependency is added to your production install. - Filament 3, 4 and 5. Tested against every major on PHP 8.3 – 8.5, with the lowest and the newest installable PHPStan 2.x.
Requirements
| Package | Versions |
|---|---|
| PHP | 8.3 – 8.5 |
| PHPStan | 2.1+ |
| Filament | 3, 4, 5 |
Macros are read from Filament at analysis time, so they must be registered when PHPStan runs. Larastan does that for you: it boots your Laravel application, which runs the service providers that register them.
Installation
Install the package as a development dependency:
With phpstan/extension-installer (Larastan setups usually have it) there is nothing else to do. Otherwise include the extension in your phpstan.neon:
Usage
Register macros as usual — typically in a service provider's boot() — and type the closure: its parameter and return types are what PHPStan will use.
Without Larastan
Register the macros before analysis with a bootstrap file:
Good to know
- A closure without a return type is analysed as returning
mixed, just like with Larastan's macros — add the return type. - Macros are exposed as instance methods. Calling a Filament macro statically (
TextInput::myMacro()) is still reported. - Only Filament's
Macroableis handled here; Laravel'sMacroable(collections, requests, Eloquent builders, …) stays Larastan's job, so both work side by side.
Development
The macros the type-inference tests analyse are registered in tests/bootstrap.php; add a case there and an assertType() to tests/Types/data/macros.php.
Upgrading
Breaking changes and how to migrate are described in UPGRADING for every major version.
Changelog
See CHANGELOG and GitHub releases for what has changed recently.
Contributing
See CONTRIBUTING for details.
Security vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). See License File for more information.