ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

PHP CS Fixer

by adael ALL

Run php-cs-fixer code formatter to format php code from your favorite text editor

Labels php, formatting

Details

Installs

  • Total 28K
  • Win 14K
  • Mac 8K
  • Linux 6K
Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11 Mar 10 Mar 9 Mar 8 Mar 7 Mar 6 Mar 5 Mar 4 Mar 3 Mar 2 Mar 1 Feb 29 Feb 28 Feb 27 Feb 26 Feb 25 Feb 24 Feb 23 Feb 22 Feb 21 Feb 20 Feb 19 Feb 18 Feb 17 Feb 16 Feb 15 Feb 14 Feb 13 Feb 12
Windows 0 1 2 2 0 5 5 3 1 3 4 0 3 1 5 1 2 0 2 2 0 6 3 3 2 3 1 2 1 5 3 3 1 2 4 4 4 2 6 3 2 1 2 2 7 5
Mac 0 0 1 0 1 2 2 1 3 3 0 0 0 0 0 3 2 2 1 1 0 2 1 0 0 1 0 2 2 0 3 0 0 2 0 0 4 1 3 0 2 2 0 0 3 1
Linux 0 1 2 1 2 0 2 0 1 0 3 1 1 3 1 1 1 0 2 1 0 2 1 2 1 0 0 1 0 1 0 1 2 1 3 0 2 1 1 1 3 1 2 0 0 0

Readme

Source
raw.​githubusercontent.​com

Sublime PHP CS Fixer

This is a plugin for Sublime Text ¾, to format PHP code through php-cs-fixer command on any view.

Features

  • It works inside a temporal view (ie: on an new, non-saved file)
  • Fast
  • Easy
  • Configurable through rules or a config file
  • Tested on Windows and Linux

Configuration

You have to install the actual php-cs-fixer (the actual tool made by sensiolabs, not this plugin)

You can install php-cs-fixer directly with composer by running:

composer global require friendsofphp/php-cs-fixer

Also you can create a config file as explained here https://github.com/FriendsOfPHP/PHP-CS-Fixer

for example in: $HOME/.php-cs-fixer.php

<?php

return (new PhpCsFixer\Config)
    ->setRules([
        '@Symfony' => true,
        'array_syntax' => ['syntax' => 'short'],
    ]);

If you've created a config file, you have to configure its path in the plugin's settings.

In Menu -> Preferences -> Package Settings -> PHP CS Fixer -> Settings - user

{
    "config": "/path/to/.php-cs-fixer.php"
}

When using multiple projects with different configurations, it's possible to configure the path relative to the Sublime project folder:

{
    "config": "${folder}/.php-cs-fixer.php",
    "php": "${packages}/User/php",
    "path": "${packages}/User/php-cs-fixer.php"
}

It's also possible to specify multiple config paths. In that case, the first readable file is used:

{
    "config": [
        "${file_path}/.php-cs-fixer.php",
        "${folder}/.php-cs-fixer.php",
        "/path/to/.php-cs-fixer.php"
    ]
}

See extract_variables in the Sublime API Reference for the supported replacement variables. The value of the ${folder} points the path of the first project in Sublime API. Here, it's beforehand replaced with the path of the project the target file belongs.

Please note:

  • rules and config directives are excluding.
  • This plugin don't try to find the config file automatically. If you want to create a config file, you have to specify its path in the plugin settings.

Rules

{
    "rules": {
        "@PhpCsFixer": true,
    },
    // or
    "rules": "@PhpCsFixer",
    // or
    "rules": [
        "@PhpCsFixer"
    ]
}

Please note that rules and config directives are excluding.

For more information see: https://github.com/FriendsOfPHP/PHP-CS-Fixer#usage

Exclude files

Since all php files are passed directly to the php-cs-fixer executable, a configured PhpCsFixer\Finder gets ignored. In order to exclude files from php-cs-fixer, you can use the “exclude” setting:

{
    "exclude": [
        ".*[\\\\/]vendor[\\\\/].*", // vendor-path (used by Composer)
        ".*\\.phtml$" // files ending with ".phtml"
    ]
}

The exclude-filter uses python regular expressions. For more information see: https://docs.python.org/2/library/re.html

On Windows:

The plugin tries to find the executable in:

%APPDATA%\composer\vendor\bin\php-cs-fixer.bat

If it isn't working, you can locate your composer global packages path by running:

composer config -g home

On Linux:

After installing php-cs-fixer you have to specify the full path to the executable in the configuration page.

The plugin tries to find the executable in:

$HOME/.composer/vendor/bin/php-cs-fixer

However, if it isn't working, you can create a symbolic link to the php-cs-fixer executable

ln -s $HOME/.composer/vendor/bin/php-cs-fixer $HOME/bin/php-cs-fixer

Note

I've checked this on Linux and Windows, but I cannot check it on OSX. I'll thank you if someone tells me if it's working on OSX and give me some details on how to configure it.

Acknowledgements

I would like to thank to sensiolabs and contributors for their awesome package. It works flawlessly. All the work here belongs to them.

Check them at:

I'd also learned some of the sublime package structure from: