28
JunLaravel Pint is an opinionated PHP code-style fixer for minimalists. Pint is built on top of PHP-CS-Fixer and makes it simple to ensure that your code style stays clean and consistent.
Laravel Pint requires PHP 8.0+.
You may use Composer to install Pint into your PHP project:
composer require laravel/pint --dev
Once Pint has been installed, the pint binary will be available in your project’s vendor/bin
directory:
./vendor/bin/pint
When running Pint, it will output a list of files that have been fixed. It is possible to see the changes made in more detail using the -v option:
./vendor/bin/pint -v
In addition, if you would like Pint to simply inspect your code for style errors without actually changing the files, you may use the –test
option:
./vendor/bin/pint --test
By default, Pint does not require any configuration and will fix code style issues in your code by following the opinionated coding style of Laravel.
However, if you wish to customize the presets, rules, or inspected folders, you may do so by creating a pint.json file in your project’s root directory:
{
"preset": "laravel"
}
In addition, if you wish to use a pint.json
from a specific directory, you may use the --config option:
pint --config vendor/my-company/coding-style/pint.json
Presets defines a set of rules that can be used to fix code style issues in your code. By default, Pint uses the laravel preset, which fixes issues by following the opinionated coding style of Laravel.
However, you can use a different preset by passing the –preset
option:
pint --preset psr12
If you wish, you may also set the preset in your project’s pint.json file:
{
"preset": "psr12"
}
The currently supported presets are: laravel, psr12, and symfony.
Rules are style guidelines that Pint will use to fix code style issues in your code. As mentioned above, presets are predefined groups of rules that should be perfect for most PHP projects, so you typically will not need to worry about the individual rules they contain.
However, if you wish, you may enable or disable specific rules in your pint.json
file:
{
"preset": "laravel",
"rules": {
"simplified_null_return": true,
"braces": false,
"new_with_braces": {
"anonymous_class": false,
"named_class": false
}
}
}
For more details, Visit Github
Published at : 28-06-2022
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.
Launch project