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.
What are Coding Standards? Think of coding standards as a set of rules, techniques, and best practices to create cleaner, more readable, more efficient code with minimal errors. They offer a uniform format by which software engineers can use to build sophisticated and highly functional code.
In the Settings dialog, go to Editor > Inspections. From the inspections screen, expand the PHP | Quality tools node and enable “PHP CodeSniffer validation”. In the configuration pane that is now enabled, select “Custom” from the “Coding standard” dropdown, locate the ruleset configuration ( phpcs.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With