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

PHP CS Fixer

by adael ST2/ST3

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

Labels php, formatting

Details

Installs

  • Total 4K
  • Win 2K
  • OS X 1K
  • Linux 792
Oct 24 Oct 23 Oct 22 Oct 21 Oct 20 Oct 19 Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9
Windows 6 20 10 11 20 22 14 21 19 8 8 12 11 7 15 16 12 10 9 12 15 13 16 12 10 12 7 19 21 18 5 12 24 19 22 23 23 10 20 26 16 27 16 12 15 16
OS X 1 8 6 9 10 7 7 8 6 4 2 11 8 15 11 9 2 12 21 10 8 11 8 12 5 11 15 32 20 12 13 8 16 14 19 20 27 9 11 20 26 14 17 5 10 4
Linux 0 9 5 3 8 5 8 6 12 2 6 5 7 2 7 9 7 6 11 5 12 7 12 2 4 4 10 12 9 11 6 3 8 19 15 15 12 4 5 9 17 11 7 5 6 6

Readme

Source
raw.​githubusercontent.​com

Sublime PHP CS Fixer

This is a plugin for Sublime Text 3 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/.phpcsfixer

<?php
return PhpCsFixer\Config::create()
->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/.phpcsfixer"
}

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

{
    "config": "${folder}/.php_cs.dist"
}

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

{
    "config": [
        "${file_path}/.php_cs",
        "${file_path}/.php_cs.dist",
        "${folder}/.php_cs",
        "${folder}/.php_cs.dist",
        "/path/to/.phpcsfixer"
    ]
}

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 that 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.

Although you can configure the rules directly on your plugin settings, it's recommended to create the config file, as it's easier to configure every rule than using the 'rules' directive in the plugin settings.

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: