How to install and configure php-cs-fixer on your C9 workspace.
We and our team at ICF Church love to develop with Cloud9 because of the great sharing and collaborating features. We can create, clone and share our development stack in minutes for others to work on the same project. The need to configure and run a local stack of Apache, MySQL, PHP etc is gone — simply share a url and others are coding happily along…
The missing Feature
One of the things I was missing was automatic code formatting for PHP code — something really useful if your are working with lots of people on the same project. There is an option “Custom Code Formatter” in the PHP settings of the project-preferences, but it was not obvious how it worked and there was nothing to be found on the web.
Download the formatter from Github to your workspace:
$ wget wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -O php-cs-fixer -O ~/php-cs-fixer
Put it into your ~/bin folder:
$ mkdir ~/bin; mv ~/php-cs-fixer ~/bin
Make it executable:
$ chmod a+x ~/bin/php-cs-fixer
Configure your project settings to use the formatter with the desired rules:
php-cs-fixer fix "$file" --rules=@Symfony,@PSR2
Voilà. From now on, every time a file gets saved, it will be automatically checked and formatted according to the defined rule-set. No more different coding-styles across your project.