How to configure laravel pint and how does it works

Updated 5 December 2023

Laravel Pint is hotest package and CLI tool developed by the Laravel team, which is wrapper around PHP CS Fixer that is my go-to code standards tool. It is fixes coding styles to make the code more readable for developers. It is a package that is included in Laravel 9.x.x and latest verion and it is built on top of the PHP-CS-Fixer package. It can be used in both fresh Laravel applications and old ones.

It will be very usefull, especially when you have a team because team members will be avoiding using different coding styles.

Installation of Laravel Pint.

Laravel pint requires PHP version 8, if you install it on a lower PHP version you may get an error in the composer.

After installation, you can choose two ways that the Laravel Pint package offers. First one is , you can directly allow the package to make changes in your project, and second one is, you can ask the package to tell you what changes will be implemented in your project to fix the coding style or to follow the PSR standards.

If you want Pint to fix coding styles without letting you know then run the below command.

(i). Align Multiline Comments

This rule align_multiline_comment will allow you to fix any comments that I call “borked”. They have all gone out of alignment and look weird. It is not a significant thing in terms of your code, but it is an annoyance when reading through it as your eyes will be drawn to it instead of what you want to focus on.

(ii). Array Indentation

The rule array_indentation will allow you to fix any arrays you are creating that has, again, become “borked” for some reason. Another code cleaning rule that will tidy up where spaces may be used in the wrong place etc. etc.

(iii). Array Syntax

The array_syntax rule is one that you may not need, depending on the age of your code. This rule will change the old array() syntax to the new [] syntax. I keep this in case I have old code or am working with multiple developers who may fall into old habits.

(iv). Blank Line After Namespace

The blank_line_after_namespace rule is a housekeeping rule that I use to ensure that there is always a blank line under the namespace declaration on any class.

(v). Blank Line After Opening Tag

The blank_line_after_opening_tag rule is similar to the previous rule but enforces a blank line after the opening PHP tag. I like to keep my code organized and uniform – these rules enable this.

(vi). Combine Consecutive Issets.

The combine_consecutive_issets rule is one that taught me that I could use more than one argument in an isset check -which was something new to me. This will convert any code that combines one or more isset checks into one clean check.

(vi). Combine Consecutive Unsets.

Laravel Pint package helps to clean the code and it fixes the coding styles. In this article, we have learned about installation and usage of Laravel Pint.

If you’re looking to build something amazing with Laravel and Vue, why not consider hire laravel developers who can bring your vision to life? You can also checkout our Bagisto Extensions.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home