PHP Mess Detector Support in PhpStorm 6.0

Posted on by rustam.vishnyakov

PhpStorm has added one more tool to its list of external code quality validators: PHP Mess Detector.

Similarly to PHP Code Sniffer, the tool is not bundled with the IDE, you have to install it manually. Fortunately it’s not so difficult, in most cases it’s sufficient to follow the instructions here. Make sure that PHP Mess Detector works from command line and if run without parameters gives something like this:


Mandatory arguments:
1) A php source code filename or directory. Can be a comma-separated string
2) A report format
3) A ruleset filename or a comma-separated string of rulesetfilenames
...

Now we are ready to set it up in PhpStorm. Go to Settings | PHP | Mess Detector and specify tool’s startup script (phpmd) location and other parameters like timeout:

Click “Validate” at the end to make sure that a path to phpmd is set correctly. You should get a message “PHPMD @package_version@ by Manuel Pichler”.

The next step is to set up PHP Mess Detector inspection. Choose Settings | Inspections | PHP | PHP Mess Detector Validation like it is shown on the picture below. Enable some built-in validation rules (code size, naming etc.) to start with.

Click “OK” in Settings and open some PHP file in the editor. At this point you may start getting some annotations with messages having “phpmd” prefix:

You can also set up your own custom rules by adding a ruleset.xml file as shown below:

Adding multiple ruleset.xml files is possible too. If ruleset files are located under the project root, they can be shared with a team via VCS.
And basically this is it!

We would very much like to hear back from you about this feature and its implementation. Please add your bug reports and feature requests in YouTrack.

Develop with pleasure!
– JetBrains Web IDE Team

Comments below can no longer be edited.

8 Responses to PHP Mess Detector Support in PhpStorm 6.0

  1. Simon says:

    December 6, 2012

    I installed phpmd via pear on Windows. When I try to validate the install with phpstorm, I keep getting the error: Cannot run program “C:\Program Files (x86)\PHP\phpmd”: CreateProcess error=193, %1 is not a valid Win32 application
    Any ideas whats wrong?

    • rustam.vishnyakov says:

      December 6, 2012

      You need to run phpmd.bat, phpmd without extension is a linux script.

    • Vasily Bezruchkin says:

      December 6, 2012

      Hi,

      Yes, please setup your link to phpmd.bat file. It worked fine for me.

      Thanks guys @jetbrains! I adore your dracula theme 🙂

  2. Simon says:

    December 6, 2012

    Thank’s for the tip guys, that solved the problem.

  3. Ben Arnette says:

    December 11, 2012

    Totally unrelated, but annoying:

    Most links to the PHPStorm blog on the site point to some old version:

    https://www.jetbrains.com/blogs/webide/

    They should point to:

    http://blog.jetbrains.com/webide/

    • Mikhail Vink says:

      December 11, 2012

      Could you please specify any page actually having a link to a wrong blog?

  4. Jurgen says:

    December 20, 2012

    I installed phpmd using composer. (win32)
    When I try to validate the phpmd inegration in hpstorm using the phpmd.bat file in the vendor/phpmd/phpmd/src/bin (installed by composer), it doesn’t work….
    I see :
    @php_bin@ is not recognized as a command…

    Am I missing some configuration ?

    • kyriakos says:

      January 6, 2013

      that happens because php.exe is not in the system’s path. either add it to the search path environment variable or open up phpmd.bat and where it calls php.exe add the absolute path in front of php.