Laravel Pint's Laravel preset now includes the fully_qualified_strict_types rule, which automatically replaces fully qualified class names (FQCNs) with short class names and adds the corresponding use statements. The rule was added by Nuno Maduro and applies to both code and PHPDoc annotations.
What the Rule Does
When you reference a class using its fully qualified name, the rule converts it to a short name and adds a use import at the top of the file. For example, a typical Laravel model might look like this:
class User extends Authenticatable{ /** @use HasFactory<\Database\Factories\UserFactory> */ use HasFactory, Notifiable; protected function casts(): array { return [ 'email_verified_at' => \Illuminate\Database\Eloquent\Casts\Attribute::class, ]; }}
After running Pint, it becomes:
use Database\Factories\UserFactory;use Illuminate\Database\Eloquent\Casts\Attribute; class User extends Authenticatable{ /** @use HasFactory<UserFactory> */ use HasFactory, Notifiable; protected function casts(): array { return [ 'email_verified_at' => Attribute::class, ]; }}
The rule handles FQCNs in type hints, return types, PHPDoc tags (@param, @return, @var, @throws), and inline code references.
How to Use It
If your project uses 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 your pint.json, you can add the rule manually:
{ "preset": "psr12", "rules": { "fully_qualified_strict_types": { "import_symbols": true } }}
Setting import_symbols to true tells the fixer to automatically add use statements for any FQCNs it finds, rather than only shortening names that already have a corresponding import.
Things to Know
This rule will affect existing projects the first time you run Pint after updating. Expect a one-time diff across your codebase as FQCNs are replaced with imports. The changes are cosmetic and don't affect runtime behavior.
For the full rule documentation, see the Symfony PHP-CS-Fixer docs.