PHP code example of happenv-com / filament-phpstan-macros
1. Go to this page and download the library: Download happenv-com/filament-phpstan-macros library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
happenv-com / filament-phpstan-macros example snippets
// A service provider
Field::macro('translatableLabel', function (string $key): Field {
/** @var Field $this */
return $this->label(__("fields.{$key}"));
});
// Anywhere in the app
TextInput::make('title')->translatableLabel('title')->maxLength(100);
TextInput::make('title')
->translatableLabel('title') // the macro — its error is ignored
->copyable(copyMessage: 42) // wrong argument type
->maxLenght(100); // typo
use Filament\Forms\Components\Field;
use Filament\Forms\Components\TextInput;
use Filament\Tables\Columns\Column;
use Filament\Tables\Columns\TextColumn;
// Fluent: typed to return an ancestor, so the chain keeps the caller's type.
Column::macro('sortableAndSearchable', function (): Column {
/** @var Column $this */
return $this->sortable()->searchable();
});
// Returning a value: kept as declared.
Field::macro('translationKey', function (): string {
/** @var Field $this */
return "fields.{$this->getName()}";
});
TextColumn::make('name')->sortableAndSearchable()->limit(50); // still a TextColumn: limit() is known
TextInput::make('title')->translationKey(); // string
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.