How to install and configure php-cs-fixer on your C9 workspace.

Get nicely formated PHP code for Cloud9 IDE

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.

There is the Setting — But what do we put there?!

Fortunately, my teammate knew a nice formatter and after some probing around, I found a working solution:

The Solution

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" [email protected],@PSR2
Add the above configuration to “Custom Code Formatter” under PHP

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.


Thanks for reading.

If you like this story please clap :) — like to stay up to date? follow us


MEDIUM — Where we share.
GITLAB— Where we collaborate.
FACEBOOK — Where we connect.

NoëI

NoëI

I’m a full-stack developer living and working in Switzerland. I love to craft elegant and fast websites using powerfull tools that look great and are easy to use. My passion for good looking and even better working software lead me to try new things all the time – I guess, that makes me a classic digitalpixelnerd.