Home » Php » What do you recommend for a PHP Coding Standards tool/system/program?

What do you recommend for a PHP Coding Standards tool/system/program?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I’m working on a PHP project with several developers, each who has their own style. The styles differ significantly, and can make the code really hard to read, and everyone is in agreement that we need to standardize our style.

The issue I’m having is that I can’t find any good program or system to help enforce standards for PHP. I’ve used a number of programs in the past for C++ and Java, and I’m a huge checkstyle fan, but I can’t find anything so elegant for PHP.

What program, tool, or system would you recommend to help developers adhere to a common set of PHP coding standards? Additionally, it would be great if the solution also handled PHP embedded in XHTML, but that is not a requirement.

How to&Answers:

PHP_CodeSniffer seems like a great tool. A project I was affiliated with used the Zend Framework coding standard as a basis for our own, and we looked into using it.

However, our deadline did not allow much leeway for experimenting with new tools, so we never got into using it past initial testing.

Answer:

I used in the past phpCodeBeautifier. It does not have lots of options, but it gets the job done to certain point and helps keeping standard code.

It’s run from command line and, provided your IDE supports external formatters, you could integrate with that, or create a script to run on all your files.

Alternatively, if you use Eclipse or you don’t but plan to run this occasionally, you could use Eclipse with its PHP plugin. You can re-format code inside folders with just a couple of clicks.

Answer:

I faced the same problem before, but not after I use Zend Studio for Eclipse

http://www.zend.com/en/products/studio/

Using Zend Studio gives the following benefits:

  1. Code that is 100% free from syntax errors

  2. Code that is formatted using PHP or Zend Standard. Just Press Ctrl+Shift+F and everything formats nicely.

  3. Detect potential warning, such as security warning for variable files inclusion, such as:

    include $file;

You can find a lot more details on their website.
Now I can’t work without Zend Studio.

Answer:

If you have several developers, you must be using some sort of version control and continuous integration, right? I use PHP_CodeSniffer (with Zend rules and automatic tab-to-spacing changes) to watch for coding violations and report them using phpUnderControl. If you aren’t using continuous integration, there is a great guide over at iBuildings about setting it up along with PHP_CodeSniffer, phpUnit, and phpDocumetor: http://techportal.inviqa.com/2009/03/03/getting-started-with-phpundercontrol/

Answer:

I’ve used coding standard part of Zend in the past and it has worked pretty good for me. You can find it at Zend Coding Standard providing you are using Zend to develop your code.