Skip to content

Instantly share code, notes, and snippets.

@kandran
Last active November 19, 2018 08:28
Show Gist options
  • Save kandran/2154e0ef49bd25d28e90 to your computer and use it in GitHub Desktop.
Save kandran/2154e0ef49bd25d28e90 to your computer and use it in GitHub Desktop.
Use php-cs-fixer with phpstorm file watcher

Auto use php-cs-fixer at save with PHPStorm and file watcher

  1. Open settings ( ctrl + alt + s)
  2. Menu file watchers
  3. Import watchers.xml
  4. Change settings like path for php and php-cs-fixer
  5. Enjoy ! PSRize at save.

NB: File watchers are linked to a specific project, so we have to re-import them for each project. External tools have IDE scope but we couldn't run them automaticaly - we could set a key bind.

<?xml version="1.0" encoding="UTF-8"?>
<TaskOptions>
<TaskOptions>
<option name="arguments" value="C:\php-5.5\php\php-cs-fixer.phar fix $FileDir$/$FileName$ --level=psr2" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" value="" />
<option name="exitCodeBehavior" value="ALWAYS" />
<option name="fileExtension" value="php" />
<option name="immediateSync" value="true" />
<option name="name" value="cs fixer" />
<option name="output" value="" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="false" />
<option name="passParentEnvs" value="true" />
<option name="program" value="C:/php-5.5/php/php.exe" />
<option name="scopeName" value="Project Files" />
<option name="trackOnlyRoot" value="false" />
<option name="workingDir" value="$ProjectFileDir$" />
<envs />
</TaskOptions>
</TaskOptions>
@Ejdems666
Copy link

Why is the programme php and not php-cs-fixer? I switched that and it worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment