PHP Beautifier and me

Being still in the look-out for a PHP coding standard to adopt one of the main prerequisites is that its adoption and maintenance should be easy. This means that I’d like a tool to do it in my place when possible.
I’ve adopted Sublime PHP Code Sniffer as the tool to spot code non compliant to the standard, I’ve written about it in an earlier post, and really in hate-love relationship with it at the moment.

Read the documentation

What allowed me to get up and running with PHP Code Sniffer was really reading its documentation to find out that it actually needed, and in a later stage allowed, configuring. This means that I’ve stumbled, in the plugin settings, into the line that would have launched php-cs-fixer (”PHP Coding Standards Fixer “) at each save

// PHP-CS-Fixer settings

// Fix the issues on save
"php_cs_fixer_on_save": true,

// Show the quick panel
"php_cs_fixer_show_quick_panel": true,

// Path to where you have the php-cs-fixer installed
"php_cs_fixer_executable_path": "/usr/local/bin/php-cs-fixer",

// Additional arguments you can specify into the application
//
// Example:
// {
//     "--level": "all"
// }
"php_cs_fixer_additional_args": {
"--level": "all"
},

PHP Coding Standards Fixer?!

My dreams of an automatic code standard fixer fulfilled I’ve downloaded the tool and launched it. As listed in its usage documentation the tool will apply psr0, psr1 and psr2 coding standards to the code and to me this meant I had found my standard.
Or rather I had found to tool to enforce it.
Being as lazy as can be concealed in the “I automate” sentence I’ve fired it, found it working but also found it having little effect. Little as just one line change and not fixing any code below the method definition level.

Again, read the documentation

Until 3 weeks ago I used Sublime Text PHP Beautifier plugin to format the code but really did not like the way it nested arrays on newlines: I’m all for code readability, that’s the standard’ selling points, but not to the point of producing code columns. If only I could keep PHP Beautifier formatting power and apply my standard…
Of course I can.

PEAR? PSR?

I had chosen to stick with PSR-2 standard because I thought PHP Code Sniffer Fixer would have allowed me to do to my code what DocBlockr did for comments: automagically make my code look cleaner and more organized.
Having fell short with that expectation I’m considering to stick with PEAR coding standards just because PHP_Beautifier makes it that easy out of the box.
Yes: I have no shame in admitting any standard is better than none and in my lone freelance web developer scenario any standard will do. I even suspect code properly formatted to a standard could be converted to another standard via algorithms with little pain.

So PHP_Beautifier comes with PSR standards?

No, it doesn’t but comes with PEAR’ ones.
Getting the code into PEAR coding standard land is as difficult as launching PHP_Beautifier with the arguments (copied from documentation)

php_beautifier -l "Pear()" index.php index_pear.php

or using it via its Sublime Text plugin incarnation in its default configuration.
I do not like PEAR coding standard as a whole but I do like comment blocks for files, classes and functions which are not, at the moment, enforced by PSR standards.

My current set-up

Right now I’m using PHP_Beautifier to format code to Pear standards, using snippets and a DocBlockr modification to add file, class and method comment blocks as detailed in this post of mine.
I do not like this solution very much and am digging PHP_Beautifier options and possibilities to come up with a solution that will allow me to format code to PSR standards instead. Personal taste.