Friday, November 13, 2015

PHP-CS-Fixer in PHPStorm with File Watcher

First of all, install php-cs-fixer:


wget http://get.sensiolabs.org/php-cs-fixer.phar -O php-cs-fixer
sudo chmod a+x php-cs-fixer
sudo mv php-cs-fixer /usr/local/bin/php-cs-fixer



Second have a project-specific php-cs config file. As an example take a look here.


In PHPStorm click "File" -> "Settings" -> "Tools" -> "File Watchers"

Fill out the provided view:

Name: PHP CS Fixer
Description: fixes php code style
Show console: Error
File type: PHP
Scope: Project Files
Program: /usr/local/bin/php-cs-fixer
Arguments: --config-file=$ProjectFileDir$/.php_cs fix $FileDir$/$FileName$ -v --diff --dry-run
Working directory: $ProjectFileDir$

It should look like this:

PHPStorm Settings


Hint: You can also ommit the --dry-run option, to let PHP-CS-Fixer automatically fix your code.

3 comments:

  1. thx, one think yet: why should the wather not fix directly the violation at lookup?

    ReplyDelete
  2. My marketing professor asked us to choose a brand, analyze it's social media campaign from a psychological perspective and write a ten page essay on how effective this campaign has been to the business and if it can be applied in any other company. Writer from ghost writer scientific paper service came up with a beautiful essay suggesting tips that would make a company's social media influence most effective and it earned me an A. This is my best grade since I joined college.

    ReplyDelete