- Download PHP Mess Detector. The easiest ways to do that is use the Composer Dependency Manager. See Using Composer Dependency Manager.
- Make sure the PHP bundled plugin is enabled By default the plugin is active. If not, enable it on the Plugins page of the Settings dialog box.
- Open the project settings, and click Mess Detector under the PHP node.
-
In the PHP Mess Detector path text box, specify the location of the Mess Detector start-up script phpmd.bat for WIndows and phpmd for Linux.
Type the path manually or click the Browse button
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. If validation passes successfully, PhpStorm displays the information on the detected Mess Detector version.
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.
- Open the project settings, and click Mess Detector under the PHP node.
-
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 - 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.
- Open the project settings, and click Inspections.
- On the Inspections page that opens, select the PHP Mess Detector validation check box under the PHP node.
-
On the right-hand pane of the page, configure the PHP Mess Detector tool using the controls in the Options area:
- 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.
- Appoint the rules to apply.
You can have predefined rules applied or define your own custom set of rules.
- Open the project settings, and click Inspections.
- On the Inspections page that opens, select the PHP Mess Detector validation check box under the PHP node.
-
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:
-
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
.
-
In the Custom rulesets area,
click the Add Rule button
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.
-
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
-
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 run the inspection, choose on the main menu. Specify the inspection scope and profile.
- 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.
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
.
-
To remove all the files from the list, click the Clean the list button
.
