Search code examples
phpcloud9-ideformattercloud9

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.


Solution

  • 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"
    },
    ...