Sharing PHP-CS-Fixer Rules Across Projects and Teams

Tim MacDonald shares a way to sharing PHP-CS-Fixer rules across your projects. It involves in setting up on repo/package that contains the rules and a little helper class that takes in a PhpCsFixer\Finder instance (along with optional extra rules).


namespace TiMacDonald;

use PhpCsFixer\Config;
use PhpCsFixer\Finder; 

function styles(Finder $finder, array $rules = []): Config {
  $rules = array_merge(require __DIR__.'/rules.php', $rules);

  return Config::create()

Once required in your actual project – using Composer – you have that project’s .php_cs.dist call the styles function:


$finder = PhpCsFixer\Finder::create()

return TiMacDonald\styles($finder);


Sharing PHP-CS-Fixer Rules Across Projects and Teams →

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.