User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active

Crazy tasty spiderI had recently to switch from geany code editor to visual studio code (further VS Code). I had my geany setup to use joomla coding standards for my code formatting. I used phpcs to inform me on problems. I didn't know how to use php-cs-fixer to automatically fix issues before and I'd like to add this function.

Since I code not only for Joomla, I need to use PSR2 coding standards for non-joomla code and to use PSR2 for other PHP projects.

For example in PSR2 coding standard a statement should look like this

if (true) {
    echo "yes';

In Joomla, the brace must be on the new line.

if (true)
    echo "yes';

The solution was rather tricky for me. So I write this note also for myself for later reference. I had to install somethings globally, system-wide, and some only per joomla workspace (joomla installation folder where I develop my extensions). I use OpenSuSE linux, but this would not make much difference to apply the steps for another OS.

 So after installing VS Code, I had to install two plugins (in fact I use much more, but the only two concern the topic).

  • vscode-phpcs to check my code formatting problems (see the phpcs result screenshot to get the idea how it works)
  • vscode-php-cs-fixer to try to automatically fix most code formatting incosistency (press a keyboard shortcut and most braces, indents, missing/extra spaces etc. are fixed automatically)

Both VS code extensions would not work without some dependency software installed.

First of all we need to install phpcs itself. The vscode-phpcs tells us to install it system-wide using pear.

sudo pear install PHP_CodeSniffer

Alas composer global require "squizlabs/php_codesniffer=*" would not work with the VS Code plugin. The plugin doesn't see the executable file elsewhere except /usb/bin/phpcs. So pear installation is a must. And it can be installed per project via composer, which should also work.

PHP-CS-Fixer installation was done by using composer composer global require friendsofphp/php-cs-fixer

I also updated the PATH variable. Added to ~/.bashrc line export PATH="$PATH:~/.config/composer/vendor/bin"

But VS Code didn't see the php-cs-fixer executable with error: PHP CS Fixer: spawn php-cs-fixer ENOENT. executablePath not found.

On some reason though php-cs-fixer command is accessible from anywhere, VS Code plugin demands FULL path to it. So in your VS code settings add line

"php-cs-fixer.executablePath": "/home/gruz/.config/composer/vendor/bin/php-cs-fixer",


After this both PHP linitng via phpcs and php-cs-fixer started to work in VS Code for PSR2. (default is PSR2).

Next the task was to make special behavior for a joomla installation.

First of all I had to install Joomla coding standards. The stable version supports only older PHPCS 2.x series, while actual is PHPCS 3.x. So according to the Joomla coding standards docs (which didn't work as described) and manual investigation I installed the latest Joomla coding standards:

Updated my /home/gruz/.config/composer/composer.json by adding 2 lines:

"minimum-stability": "alpha"


"require-dev": {

     "joomla/coding-standards": "dev-3.x-dev",


My global composer.json at the moment is

Surely for Joomla you don't need the line I have "laravel/installer": "^1.5".

Run composer global update

Next we must add the Joomla Coding Standards to the phpcs configration.

sudo phpcs --config-set installed_paths ~/.config/composer/vendor/joomla/coding-standards/

To check if phpcs sees the coding standards, run phpcs -i.The response should be like The installed coding standards are MySource, PEAR, PSR1, PSR2, Squiz, Zend and Joomla

Next we need to make two things for the Joomla folder (VS Code workspace should be tied to your Joomla folder)

In your joomla VS Code workspace set default phpcs standard to Joomla


Place php-cs-fixer rules file to the joomla root

The file should be named .php_cs and you can find it here:

You can modify the file according to your needs. See docs:

Alas, not everything is possible to fix in such a way. For example in Joomla Coding Standards there should be a blank line after a statement in curly braces. Php-cs-fixer has an option to add a blank line before a statement, but not after it.


During investigating I had several errors.

phpcs: Unable to locate phpcs. Please add phpcs to your global path or use composer depency manager to install it in your project locally.

The PHP CodeSniffer Linter server crashed 5 times in the last 3 minutes. The server will not be restarted.

VS Code didn't see phpcs installed globally via composer. Only pear installation worked.

There was aslo an error with some JSON bad characters. As far as I remember if was when I tried to install phpcs via composer under my project folder. Such an installation had output not in JSON format, which is used by the VS Code plugin. So I had to set the default output like this

./vendor/bin/phpcs --config-set report_format json

Please register to post comments.

Found a typo? Please select it and press Ctrl + Enter.
FaLang translation system by Faboba
Електронна бібліотека «Exlibris»: історичні дослідження, мемуаристика, публіцистика, художня література Українська етнографія: книги, курси лекцій, статті й матеріали, мапи, фотоальбоми, веб-ресурси Правителі України: портрети, життєписи, матеріали Твори Адріана Кащенка: романтика козацьких часів Народна війна 1917-1932

See a typo?

Select the text block and press



  • NotificationAry - get emails on Joomla content is submitted, added or changed

    Berndi Berndi 30.06.2019 11:45
    The fields %TO_NAME% and %TO_USERNAME% are empty


  • NotificationAry - get emails on Joomla content is submitted, added or changed

    Berndi Berndi 30.06.2019 11:43
    My fault, I made it


  • NotificationAry - get emails on Joomla content is submitted, added or changed

    Berndi Berndi 30.06.2019 10:46
    I did. Now I'm asking me how to put the surename into the email... :-|


  • NavigationAry - navigate between Joomla menu items like between articles using "prev - next"

    Berndi Berndi 29.06.2019 15:59
    I also miss content in %TO_NAME%


  • NotificationAry - get emails on Joomla content is submitted, added or changed

    Berndi Berndi 29.06.2019 15:15
    Hi gruz, I have the problem, that when I use the %AUTHOR% tag, the plugin dosen't send the author ...