photo credit: night life_MMV via photopin (license)

How to install PHP Mess Detector for PhpStorm on OSX

Recently I’ve been upgrading the way I write code. I’ve been programming for a while now, but there’s always room for improvement. Lucky for us developers, there are numerous tools for us we can use to aid us in our development. Things like unit testing and coding standards are great of course. But there’s also another great tool you can use to make your code more solid and maintainable: PHP Mess Detector.
PHP Mess Detector is a tool that checks if you aren’t making a mess of your code. Think of methods of hundreds of lines, classes that extend class after class after class, lack of documentation, nested loops, etc. PHP Mess Detector points out these culprits and aids into writing more manageable code. So how can we harvest such great power?

Installing PHP Mess Detector on OSX

The first thing you need to do is fire up your terminal and add the Pear channel:

To list the available packages of PHP Mess Detector do:

Now it’s time to install it:

Install the PHP Depend dependancy

If you can’t install the PHP Mess Detector pear package and you see an error like this, you need to install PHP Depend:

First add the channel:

List the available packages:

Install the correct package:

Try installing PHP Mess Detector again:

Set it up in PhpStorm

Open the configuration in PhpStorm, and navigate to “Languages & Frameworks > PHP > Mess Detector”.
Click on the  -icon in Development environment and set the path to where the PHP Mess Detector binary is installed (this usually is /usr/bin/phpmd ):

Screen Shot 2015-08-10 at 08.44.18
Navigate to “Editor > Inspections”, and enable “PHP Mess Detector validation” under “PHP”:

Screen Shot 2015-08-10 at 08.46.12

Create a ruleset.xml

Now you can use PHP Mess Detector in PhpStorm according to it’s default ruleset, or you can create your own.

Visitors give this article an average rating of 4.5 out of 5.

How would you rate this article?

Leave a Reply