PhpStorm 9.0.0 Help

Using PHP Mess Detector

In addition to built-in coding assistance, PhpStorm 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.

On this page:

Before You Start

Make sure the PHP plugin is enabled. The plugin is bundled with PhpStorm and activated by default. If the plugin is not activated, enable it on the Plugins page of the Settings dialog box as described in Enabling and Disabling Plugins.

Choosing the Mess Detector Script to Use

  1. Open the Settings dialog box by choosing File | Settings and expand the Languages & Frameworks node. 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 PhpStorm 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 dialog box by choosing File | Settings and expand the Languages & Frameworks node. Then click Mess Detector under PHP.
  3. On the Mess Detector page that opens, click browseButton 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 PhpStorm and Mess Detector, that is, the tool can be launched from PhpStorm and PhpStorm will receive problem reports from it, click the Validate button. This validation is equal to running the phpmd --version command. If validation passes successfully, PhpStorm displays the information on the detected Mess Detector version.

Configuring a Mess Detector Associated with a PHP Interpreter

  1. Open the Settings dialog box by choosing File | Settings and expand the Languages & Frameworks node. Then click Mess Detector under PHP.
  2. On the Mess Detector page that opens, click browseButton 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 add 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 browseButton and configure a remote interpreter in the Interpreters dialog box as described in Configuring Remote PHP Interpreters.

    When you click OK, PhpStorm 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

PhpStorm 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 dialog box by choosing File | Settings and expand the Languages & Frameworks node. 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 PhpStorm 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 PhpStorm 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 PhpStorm Inspection

  1. Open the Settings dialog box by choosing File | Settings or pressing Ctrl+Alt+S 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 PhpStorm 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 tool window. Errors and warnings reported by PHP Mess Detector have the phpmd prefix to distinguish them from PhpStorm 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, PhpStorm 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, PhpStorm 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

Last modified: 5 August 2015