PhpStorm 2024.1 Help

Laravel Pint

In addition to built-in coding assistance, PhpStorm integrates with Laravel Pint—a code quality tool built on top of PHP CS Fixer for detecting coding style issues in Laravel projects.

To use Laravel Pint from PhpStorm instead of the command line, you need to register it in PhpStorm and configure it as a PhpStorm code inspection. Once installed and enabled in PhpStorm, the tool is available in any opened PHP file, and no additional steps are required to launch it. The on-the-fly code check is activated upon every update in the file thus making it easy to get rid of discovered problems.

The issues reported by Laravel Pint on the fly are highlighted in the editor in the same way as the errors and warnings reported by PhpStorm's internal code inspections. When the tool is run in batch mode, the errors and warnings are displayed in the Problems tool window. Each message has the Laravel Pint prefix to distinguish it from PhpStorm internal inspections.

You can use the predefined groups of Laravel Pint rules, or enable and disable specific rules in the pint.json file.

Install and configure Laravel Pint

Install Laravel Pint with Composer

Laravel Pint is included in recent releases of the Laravel framework, so the composer.json file in your project would typically have the laravel/pint dependency record added to it. If it doesn't, add the record manually:

  1. Inside composer.json, add the laravel/pint dependency record to the require or require-dev key. To get code completion for the package name and version, press Ctrl+Space.

  2. Do one of the following:

    • Click the Install shortcut link on top of the editor panel.

    • If the Non-installed Composer packages inspection is enabled, PhpStorm will highlight the declared dependencies that are not currently installed. Press Alt+Enter and select whether you want to install a specific dependency or all dependencies at once.

Clicking the Settings button next to the package record in the composer.json editor gutter will take you to the corresponding Settings page where you can configure Laravel Pint manually.

Gutter icon for laravel_pint settings in composer.json

Configure Laravel Pint in PhpStorm

When you install Laravel Pint with Composer, PhpStorm automatically detects Laravel Pint's executable file in the vendor/bin folder and sets the PHP interpreter configured in the system path to run it.

In Settings (Ctrl+Alt+S) | PHP | Quality Tools | Laravel Pint, you can change the default PHP interpreter, set the path to a custom path to the Laravel Pint executable file, or add some options to be passed to Laravel Pint when running it in PhpStorm.

Laravel Pint settings
  • Configuration: in this field, you can change the default PHP interpreter and set the path to the Laravel Pint executable file.

    1. To change the interpreter, select the required item from the list of local and remote PHP interpreters configured in your project.

    2. To set the path to the Laravel Pint executable file, click the Browse button next to the Configuration list to open the Laravel Pint dialog and edit the fields there as described on the Laravel Pint Dialog reference page.

  • Show ignored files: use this setting to exclude files from Laravel Pint validation inspection. For more information, refer to the Quality Tools reference page.

  • Options: in this area, add the options to run Laravel Pint as a PhpStorm inspection with.

    • Reformat only uncommitted files: select the checkbox to only modify the files that have uncommitted changes.

    • Path to pint.json: specify the path to the pint.json configuration file. pint.json files are optional: they are used to enable/disable specific rules from the predefined Laravel Pint presets, or to reuse custom rulesets from PHP CS Fixer.

    • Ruleset: select one of Laravel Pint's predefined groups of rules to be used for fixing code style issues in your code.

Enable Laravel Pint as a PhpStorm inspection

Enable Laravel Pint validation in Inspections settings

  1. In the Settings dialog (Ctrl+Alt+S) , click Inspections under Editor.

  2. On the Inspections page that opens, expand the PHP | Quality Tools node and select the checkbox next to Laravel Pint validation.

    Select Laravel Pint validation checkbox
  3. On the right-hand pane of the page, configure how PhpStorm handles the Laravel Pint inspection output:

    1. Scope: choose the scope to limit the inspection application to.

    2. Severity: choose the severity degree for the inspection. The selected value determines how seriously the detected discrepancies will be treated by PhpStorm and presented in the inspection results.

    3. Highlighting in editor: choose how the issues detected by the inspection are highlighted in the editor.

Run Laravel Pint in batch mode

  1. In the main menu, go to Code | Inspect code.

  2. In the Specify Inspection Scope dialog that opens, select the inspection profile from the list, or click Configure to open the Inspections dialog and configure a new profile.

    You can also click Configure to check which fixes will be applied within the scope of the selected inspection profile, and make sure that the Laravel Pint validation inspection is enabled.

  3. View the inspection results in the Problems tool window. Errors and warnings reported by Laravel Pint are prefixed with Laravel Pint: to distinguish them from PhpStorm internal inspections.

    Laravel Pint inspection list

Fix issues detected by Laravel Pint

Fix issues by using a quick-fix

Upon detecting an issue, PhpStorm highlights it in accordance with the Laravel Pint inspection settings.

  1. Place the caret at the detected issue and click the Intention action button, or press Alt+Enter.

  2. Select Laravel Pint: fix the whole file from the popup menu. Note that this will fix all issues detected in the current file.

You can also detect issues in the batch mode, or fix them automatically with code reformatting.

Fix issues with code reformatting

You can fix issues detected by Laravel Pint by running the reformat code action.

  1. Set Laravel Pint as an external formatter in the Quality Tools settings.

    To do so, in the Settings dialog (Ctrl+Alt+S) go to PHP | Quality Tools and select Laravel Pint in the External Formatters section.

    Select external formatter
  2. Apply Reformat Code to the required file or project scope:

    • For a code fragment or a file opened in the editor, select Code | Reformat Code from the main menu or press Ctrl+Alt+L.

    • For a selected file, directory, or group of files in the Project tool window, select Reformat Code from the context menu or press Ctrl+Alt+L.

Share a custom coding style with the team

  1. Put the root directory of your coding standard under the project root.

  2. Configure Laravel Pint as a PhpStorm inspection.

  3. Appoint your coding standard.

  4. Make sure that a project profile is selected at the top of the Inspections page. Such profiles are saved in a particular project's .idea directory (for example, $PROJECT_DIR$/.idea/inspectionProfiles). For more information, refer to Configure profiles.

  5. On the Version Control page of the Settings dialog, make sure that the .idea directory is put under version control.

Exclude files from Laravel Pint inspection

When waiting for Laravel Pint response exceeds the limit specified in the Tool process timeout field in the Laravel Pint dialog, PhpStorm suggests adding the file to the ignore list.

  1. In the Settings dialog (Ctrl+Alt+S) , navigate to PHP | Quality Tools | Laravel Pint.

  2. Click the Show ignored files link.

    • To add a file, click the Add button and locate the desired file in the dialog that opens.

    • To delete a file from the list and have Laravel Pint process it again, select the file and click the Remove button.

    • To remove all the files from the list, click the Close button.

Last modified: 26 May 2024