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

  • 1.0.10
  • github.​com
  • github.​com
  • 3 months ago
  • 4 minutes ago
  • 8 months ago

Installs

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

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: