A modern PHP CS Fixer configuration for WordPress development. Maintains WordPress coding standards (tabs, Yoda conditions, spacing) while modernizing with short arrays, trailing commas, and strict comparisons.
composer require --dev aysnc/wordpress-php-cs-fixerCreate .php-cs-fixer.dist.php in your project root:
<?php
use Aysnc\WordPress\PHPCSFixer\Config;
use PhpCsFixer\Finder;
require_once __DIR__ . '/vendor/autoload.php';
$finder = Finder::create()
->in( __DIR__ )
// Or specify multiple: ->in( [ __DIR__ . '/src', __DIR__ . '/tests' ] )
->name( '*.php' )
->ignoreVCS( true )
->exclude( 'vendor' );
return Config::create()
->setFinder( $finder );Run the fixer:
# Check without fixing (dry-run)
vendor/bin/php-cs-fixer fix --dry-run --diff
# Fix files
vendor/bin/php-cs-fixer fixOverride rules by spreading Config::getRules():
return Config::create()
->setFinder( $finder )
->setRules(
[
...Config::getRules(),
'array_syntax' => [
'syntax' => 'long',
],
],
);If using alongside PHPCS with WordPress standards, and you want to override short array restrictions:
<!-- phpcs.xml.dist -->
<rule ref="WordPress">
<exclude name="Universal.Arrays.DisallowShortArraySyntax"/>
<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
</rule>