Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Beautifier / Formatter for cloud9 IDE

In my Cloud09 IDE I enabled the PHP setting "Custom Code Formatter"

But saving results in an Error: No code formatter set for php: please check your project settings there is no formatter predefined like with JS (esformatter -i "$file") and google is of no help as well...

enter image description here

How do I use this setting?

How can I install a PHP formatter on Cloud9?

My only search revealed this Pear package but it seems outdated.

like image 523
noelboss Avatar asked Dec 05 '16 10:12

noelboss


1 Answers

Download php-cs-fixer https://github.com/FriendsOfPHP/PHP-CS-Fixer to your Cloud9 Workspace:

$ wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.0.0/php-cs-fixer.phar -O ~/php-cs-fixer

Put it in your ~/bin directory:

$ mkdir ~/bin; mv ~/php-cs-fixer ~/bin

Make the file executable:

$ chmod a+x ~/bin/php-cs-fixer

Configure your IDE's Custom Code Formatter setting for PHP to use the formater with whatever rules you want:

php-cs-fixer fix "$file" --rules=@Symfony,@PSR2

That's how my ~/workspace/.c9/project.settings file looks:

...
"php": {
    "@completion": true,
    "@formatOnSave": true,
    "@formatter": "php-cs-fixer fix \"$file\" --rules=@Symfony,@PSR2",
    "@path": ".:./vendor:/usr/local/bin"
},
...
like image 149
noelboss Avatar answered Nov 03 '22 09:11

noelboss