Laravel Pint Now Converts Fully Qualified Class Names to Imports Automatically
Laravel Pint's Laravel preset now includes the fully_qualified_strict_types rule. When you run Pint, it automatically converts fully qualified class names (FQCNs) to short names and adds the corresponding use import statements at the top of each file. This applies to type hints, return types, and PHPDoc annotations including @param, @return, @var, and @throws.
What It Does
Before running Pint, a model might look like this:
protected function casts(): array
{
return [
'email_verified_at' => \Illuminate\Database\Eloquent\Casts\Attribute::class,
];
}
After Pint runs, the FQCN is replaced and the import is added:
use Illuminate\Database\Eloquent\Casts\Attribute;
protected function casts(): array
{
return [
'email_verified_at' => Attribute::class,
];
}
The changes are cosmetic - runtime behaviour is unaffected.
How to Enable It
If you use Pint's default laravel preset, the rule is already active. Update Pint and run it:
composer update laravel/pint
./vendor/bin/pint
If you use a custom preset in pint.json, add the rule manually:
{
"preset": "psr12",
"rules": {
"fully_qualified_strict_types": {
"import_symbols": true
}
}
}
Setting import_symbols to true tells the fixer to add use statements for any FQCNs it finds, not just shorten those that already have a matching import.
One Thing to Expect
The first time you run Pint after updating, expect a larger-than-usual diff if your codebase has accumulated FQCNs over time. Review the changes in your version control before committing - they will be safe, but the diff can be significant in older projects. After that initial pass, subsequent Pint runs will be back to normal.
