A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.jetbrains.com/help/phpstorm/using-php-cs-fixer.html below:

PHP CS Fixer | PhpStorm Documentation

PHP CS Fixer

In addition to built-in coding assistance, PhpStorm provides checking the source code through integration with the PHP CS Fixer tool, which detects coding standards problems in your code.

To use PHP CS Fixer 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.

Issues reported by PHP CS Fixer 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 PHP CS Fixer prefix to distinguish it from PhpStorm internal inspections.

You can have predefined rules applied or define your own custom set of rules.

Prerequisites

Prior to integrating PHP CS Fixer in PhpStorm, make sure the following prerequisites are met:

Install and configure PHP CS Fixer Install PHP CS Fixer with Composer

Before you start, make sure Composer is installed on your machine and initialized in the current project as described in Composer dependency manager.

When you install PHP CS Fixer with Composer, PhpStorm automatically downloads the necessary scripts, registers them in the IDE, and, optionally, enables and configures the corresponding code inspection.

  1. Inside composer.json, add the friendsofphp/php-cs-fixer 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:

Clicking next to the package record in the composer.json editor gutter will take you to the corresponding Settings page where you can configure PHP CS Fixer manually.

Reset PHP CS Fixer configuration

After PHP CS Fixer is initially configured, further modifications in composer.json will not affect the inspection configuration. To apply newer changes, reset the PHP CS Fixer configuration.

  1. In the Settings dialog (Ctrl+Alt+S) , navigate to .

  2. Click next to the Configuration list.

  3. In the PHP CS Fixer dialog that opens, empty the PHP CS Fixer path field.

  4. Update the project Composer dependencies by clicking Update on top of the composer.json editor panel. For more information, refer to Update dependencies.

PhpStorm will perform the PHP CS Fixer configuration anew and thus apply the changes in composer.json.

Configure PHP CS Fixer in PhpStorm

When you install PHP CS Fixer with Composer, PhpStorm automatically detects PHP CS Fixer'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) | , you can change the default PHP interpreter, set the path to a manually downloaded and installed PHP CS Fixer executable file, or add some options to be passed to PHP CS Fixer when running it in PhpStorm.

There are two ways to set up PHP CS Fixer as a PhpStorm inspection: automatically during PHP CS Fixer installation with Composer, or manually in PhpStorm's inspections settings.

Enable the PHP CS Fixer inspection with Composer

You can include the information on the default and custom PHP CS Fixer rulesets inside the scripts section of composer.json. When you install or update project dependencies, the specified rulesets will be detected and the PHP CS Fixer validation inspection will be enabled automatically.

If no ruleset is specified in the scripts section of composer.json, PhpStorm will additionally check the project root to locate the ruleset with the .php_cs or .php_cs.dist default name. If the file is present, it will be automatically selected as the inspection's Custom ruleset.

After PHP CS Fixer is initially configured, further modifications in composer.json will not affect the inspection configuration. To apply newer changes, reset the PHP CS Fixer configuration on the page of the Settings dialog (Ctrl+Alt+S) and update project dependencies.

Enable PHP CS Fixer 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 node and select the checkbox next to PHP CS Fixer validation.

    If you have installed PHP CS Fixer with Composer but the corresponding inspection is currently disabled, PhpStorm highlights its record in composer.json. Press Alt+Enter and use the provided Enable inspection quick-fix to enable the inspection and open the Inspections page.

  3. On the right-hand pane of the page, configure how PhpStorm handles the PHP CS Fixer 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.

You can also enable and disable the PHP CS Fixer validation inspection in the Settings dialog (Ctrl+Alt+S) | PHP | Quality Tools by using the ON/OFF toggle in the PHP CS Fixer section, but note that this action is applied only to the Project Default inspection profile.

  1. In the main menu, go to .

  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 PHP CS Fixer validation inspection is enabled.

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

Fix issues detected by PHP CS Fixer Fix issues by using a quick-fix

Upon detecting an issue, PhpStorm highlights it in accordance with the PHP CS Fixer inspection settings.

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

  2. Select PHP CS Fixer: 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 PHP CS Fixer by running the reformat code action.

  1. Set PHP CS Fixer as an external formatter in the Quality Tools settings.

    To do so, in the Settings dialog (Ctrl+Alt+S) go to and select PHP CS Fixer in the External Formatters section.

    External formatters are no longer run during the Code Cleanup action.

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

When you reformat code with the external formatter enabled, PhpStorm's built‑in formatter is disabled by default. To run the reformat code action with both the selected external formatter and the IDE's built-in formatter, go to (Ctrl+Alt+S) and select the checkbox in the area.

PHP CS Fixer is also run as an external formatter with reformat code on save and reformat code before commit actions.

Share a custom coding style with the team
  1. Put the root directory of your coding standard under the project root.

  2. Configure PHP CS Fixer 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 Inspection 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 PHP CS Fixer inspection

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

  1. In the Settings dialog (Ctrl+Alt+S) , navigate to .

  2. Click the Show ignored files link.

22 January 2025


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4