X

An Oracle blog about NetBeans for PHP

Static code analysis

Hi all, today we will show you how you can check quality of your PHP code in NetBeans 7.4. For this task, we use standard PHP tools PHP_CodeSniffer and PHP Mess Detector.

As always if NetBeans uses any external tool, verify IDE Options that everything is set correctly:

IDE Options

If it is, you are ready to inspect your code (one can select a PHP project or a PHP file):

Inspect Code

Inspect dialog will appear. Here, we can e.g. select only one inspection tool or create custom configuration:

Inspect Dialog

If we are ready and run the inspection (please notice that it can take a long time for big projects), analysis results are shown:

Inspection Results

As you can see, the results are categorized by files and folders so we can easily recognize which area of our project needs our attention first. If we double click any of these results, the given warning(s) is shown to us on the proper line:

Inspection Warning

If anything goes wrong (e.g. inspection is running too long), one can easily verify what each tool does exactly in the Output window:

Inspection Log

If anyone of you has a tip for another PHP code analysis tool, let us know via NetBeans Bugzilla or leave a comment here (please notice that the comments are moderated so they will not appear here immediately).

That's all for today, as always, please test it and report all the issues or enhancements you find in NetBeans Bugzilla (component php, subcomponent Code).

Join the discussion

Comments ( 21 )
  • Eli McMakin Wednesday, May 22, 2013

    Awesome! It's good to see this making it into NetBeans. I'd love to see the whole PHP community get more standardized.


  • guest Thursday, May 23, 2013

    This is really great.


  • kangcool Friday, May 24, 2013

    Are you able to set the standard per project, as I just a number of different standards


  • Tomas Mysik Friday, May 24, 2013

    To kangcool: IMHO not, one can only create custom configurations. Feel free to submit an enhancement to NB Bugzilla.

    Thanks.


  • Carlos Romel Wednesday, May 29, 2013

    Very cool. Netbeans could use plugins available at Sonar project (better, delegate to Sonar this analisys, not only for PHP but for Java and other languages what Sonar plugins have support).


  • Badanie EEG Wednesday, May 29, 2013

    This capability will facilitate a quality analysis code. I love the entry


  • guest Wednesday, May 29, 2013

    I like how http://sourceforge.net/projects/phpmdnb/ integrates this into "Action Items" that makes it easy to switch between open file tabs and have "context" be right there. Is it possible to have something similar instead of having to do "Inspect" on every open/current file?


  • Tomas Mysik Thursday, May 30, 2013

    To guest: Please, submit an enhancement to NB Bugzilla (link is in the blog post).

    Thanks.


  • gwebtools subnet calculator Monday, June 3, 2013

    We currently use Netbeans to develop our systems in PHP with Symfony framework, we will give a try to this code analysis tools.

    Thanks


  • Projektant wnętrz warszawa Wednesday, June 5, 2013

    The errors occur infrequently, you may want to report it quickly. NB development goes in the right direction. It amazes me that the IDE for Java environment got so many languages, and the product is very mature and stable.


  • taatparya Tuesday, July 16, 2013

    Really great work.

    Copy Paste Detection is another candidate. What about using this as a guide for the tools to be integrated:

    http://jenkins-php.org/


  • Tomas Mysik Tuesday, July 16, 2013

    To taatparya:

    Thanks! Please, as written in the blog post, use NetBeans Bugzilla for reporting issues and enhancements, not these comments.

    Thanks for undertanding.


  • Ben Monday, September 23, 2013

    How do you set the default standard ?

    on my computer none are available.


  • Tomas Mysik Monday, September 23, 2013

    To Ben:

    Please verify that you have installed PHP_CodeSniffer properly (its standards are got via command line).

    Thanks.


  • Stefan Friday, October 18, 2013

    It's great that it's possible to inspect the files with CodeSniffer. But it would be much better if I would be able to force NetBeans to use a specific formatting.

    I'm using PSR-2, but I'm unable to use valid multi-line method call arguments and method parameters. I have to select "never" in the wrapping options. When I select "if long" it only wraps the words which would be too long. So two parameters in one line, the other two in the second line.

    Okay, I could use "Alway", but then I have also two lines when having two short parameters. Not very beautiful. But not valid, because the first argument/parameter have to be placed in a new line, not after the parantheses. I can't find an option for new lines after the parantheses.

    And there are some other things, which causes that I can't use ALT + F to format my code so that it's PSR-2 conform.


  • guest Monday, October 21, 2013

    Is it possible to disable code analysis, or at least certain rules? I don't really want 1000 warning telling me that my methods are longer than 10 lines ...


  • Tomas Mysik Monday, October 21, 2013

    To guest: How would one do it from the command line?

    Thanks.


  • guest Wednesday, November 6, 2013

    Hello,

    is it possible to inspect a single folder of a project


  • Tomas Mysik Wednesday, November 6, 2013

    To guest: Unfortunately not.


  • guest Thursday, November 7, 2013

    I installed codesniffer in xampp using PEAR and running phpcs -i returns 7 standards installed. Unfortunately, netbeans 7.4 still does not pick them up and says no standards available. Codesniffer version is 1.5.0RC4


  • Tomas Mysik Friday, November 8, 2013

    To guest: It seems that CodeSniffer changed the output format. Please, report it as a new issue and provide output of this command:

    phpcs -i

    Thanks.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services