Laravel Code Formatting: 11 Typical Errors to Avoid
1. Removing Unnecessary Imports
It's a common oversight to leave behind unused imports, especially after copying code or making changes to classes. This oversight can be easily addressed as follows:
Set this rule:
'no_unused_imports' => true,
Then, by executing /vendor/bin/pint fix
, it will automatically clean up all those redundant imports.
2. Function Visibility Simplified
In PHP, it's essential to specify the visibility of functions, meaning whether a function is public, private, or protected. By default, functions are public, but explicitly defining visibility is considered a best practice in Laravel development.
Rule in Pint Configuration: