IntelliJ IDEA 2016.3 Help

Using PHP Mess Detector

This feature is supported in the Ultimate edition only.

In this section:

Introduction

In addition to built-in coding assistance, IntelliJ IDEA provides checking the source code through integration with the PHP Mess Detector tool, which detects potential problems related to code size, inconsistency, unused code, violation of naming conventions, poor design, etc.

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

Before you start

Make sure the PHP plugin is enabled. The plugin is not bundled with IntelliJ IDEA, but it can be installed from the JetBrains plugin repository as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.

Choosing the Mess Detector script to use

  1. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or IntelliJ IDEA | Preferences for OS X. Expand the Languages&Frameworks node, and then click Mess Detector under PHP.
  2. From the Configuration drop-down list in the Development Environment area, choose the script to use:
    • To use the script associated with a specific remote PHP interpreter, choose the name of this interpreter.
    • To use the script associated with the default project interpreter, that is, the one chosen on the PHP page of the Settings dialog box, choose By default project interpreter.
    • To use a local script, choose Local. In this case the local Mess Detector will be executed no matter which PHP interpreter - local or remote - is used in the project. Note that there can be only one Local configuration for Mess Detector because IntelliJ IDEA runs a script (phpmd.bat for Windows or phpmd for Linux) which contains a path to a PHP engine.

Configuring a local Mess Detector script

  1. Download PHP Mess Detector. The easiest ways to do that is use the Composer Dependency Manager, see Using Composer Dependency Manager.
  2. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or IntelliJ IDEA | Preferences for OS X. Expand the Languages&Frameworks node, and then click Mess Detector under PHP.
  3. On the Mess Detector page that opens, click /help/img/idea/2016.3/browseButton.png next to the Configuration drop-down list.
  4. In the Mess Detector dialog box that opens, specify the location of the Mess Detector executable phpmd.bat or phpmd in the PHP Mess Detector path text box. Type the path manually or click the Browse button browseButton.png and select the path in the dialog box, that opens. If you installed the tool through Composer, the default location is <project root folder>\vendor\bin\phpmd.bat.

    To check that the specified path to phpmd.bat or phpmd ensures interaction between IntelliJ IDEA and Mess Detector, that is, the tool can be launched from IntelliJ IDEA and IntelliJ IDEA will receive problem reports from it, click the Validate button. This validation is equal to running the phpmd --version command. If validation passes successfully, IntelliJ IDEA displays the information on the detected Mess Detector version.

Configuring a Mess Detector associated with a PHP interpreter

  1. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or IntelliJ IDEA | Preferences for OS X. Expand the Languages&Frameworks node, and then click Mess Detector under PHP.
  2. On the Mess Detector page that opens, click /help/img/idea/2016.3/browseButton.png next to the Configuration drop-down list. The Mess Detector dialog box opens showing a list of all the configured Mess Detector scripts in the left-hand pane, one of them is of the type Local and others are named after the PHP interpreters with which the scripts are associated. Click /help/img/idea/2016.3/new.png on the toolbar.
  3. In the Mess Detector by Remote Interpreter dialog box that opens, choose the remote PHP interpreter to use the associated script from. If the list does not contain a relevant interpreter, click /help/img/idea/2016.3/browseButton.png and configure a remote interpreter in the CLI Interpreters dialog box as described in Configuring Remote PHP Interpreters.

    When you click OK, IntelliJ IDEA brings you back to the Mess Detector dialog box where the new Mess Detector configuration is added to the list and the right-hand pane shows the chosen remote PHP interpreter, the path to the Mess Detector associated with it, and the advanced PHP Mess Detector options.

Specifying advanced PHP Mess Detector options

IntelliJ IDEA provides the ability to specify advanced PHP Mess Detector options and thus fine tune the PHP Mess Detector process behavior depending on the configuration of your computer and the rule sets used.

  1. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or IntelliJ IDEA | Preferences for OS X. Expand the Languages&Frameworks node, and then click Mess Detector under PHP. The Mess Detector page opens.
  2. In the Maximum number of messages per file text box, set the upper limit for the total number of messages to be reported for a file. All the messages above this limit will be rejected and IntelliJ IDEA will display the following warning right in the code:
    Too many PHP Mess Detector messages
  3. In the Tool process timeout text box, specify how long you want IntelliJ IDEA to wait for a result from PHP Mess Detector, whereupon the process is killed to prevent excessive CPU and memory usage.

Configuring PHP Mess Detector as a IntelliJ IDEA inspection

  1. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or IntelliJ IDEA | Preferences for OS X, and click Inspections under Editor.
  2. On the Inspections page that opens, select the PHP Mess Detector validation check box under the PHP node.
  3. On the right-hand pane of the page, configure the PHP Mess Detector tool using the controls in the Options area:
    1. From the Severity drop-down list, choose the severity degree for the Mess Detector inspection. The selected value determines how serious the detected discrepancies will be treated by IntelliJ IDEA and presented in the inspection results.
    2. Appoint the rules to apply.

Specifying the rules to apply

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

  1. Open the Settings dialog box, and click Inspections.
  2. On the Inspections page that opens, select the PHP Mess Detector validation check box under the PHP node.
  3. Do one of the following:
    • To use a predefined rules, in the Options area, select the check boxes next to the validations to be performed. For more details on predefined rules, see http://phpmd.org/rules/index.html.
    • To use a custom ruleset:
      1. Create and save one or several ruleset files. A valid ruleset file is an .xml file that contains the root element <ruleset> with the attribute name. For more details on custom rulesets, see http://phpmd.org/documentation/creating-a-ruleset.html.
      2. In the Custom rulesets area, click the Add Rule button add.png and select the relevant rule definition file in the dialog box that opens. When you click OK, a new item is added to the Custom rulesets list, where the File field shows the location of the selected ruleset file and the Name field shows the ruleset name retrieved from the attribute name within the <ruleset> tag.

Running Mess Detector in the batch mode

  1. To run the inspection, choose Code | Inspect code on the main menu. Specify the inspection scope and profile.
  2. View the inspection results in the Inspection Results Tool Window. Errors and warnings reported by PHP Mess Detector have the phpmd prefix to distinguish them from IntelliJ IDEA internal inspections.

Excluding files from Mess Detector inspection

When waiting for Mess Detector response exceeds the limit specified in the Tool process timeout field on Mess Detector page, IntelliJ IDEA suggests adding the file to the ignore list. This list is shown on the Mess Detector page in the Ignored files area. For each file, IntelliJ IDEA displays its name and location.

  • To delete a file from the list and have Mess Detector process it again, select the file and click the Remove file button delete.png.
  • To remove all the files from the list, click the Clean the list button close.png.

See Also

```

Reference:

External Links:

Last modified: 21 March 2017