aysnc/wordpress-php-cs-fixer

PHP CS Fixer for WordPress

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/aysnc/wordpress-php-cs-fixer

0.2.0 2025-12-13 16:10 UTC

This package is not auto-updated.

Last update: 2025-12-14 01:36:13 UTC


README

GitHub Actions Maintenance

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.

Installation

composer require --dev aysnc/wordpress-php-cs-fixer

Usage

Create .php-cs-fixer.dist.php in your project root:

<?php

use Aysnc\WordPressPHPCSFixer\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 fix

Customizing Rules

Override rules by spreading Config::getRules():

return Config::create()
	->setFinder( $finder )
	->setRules(
		[
			...Config::getRules(),
			'array_syntax' => [
				'syntax' => 'long',
			],
		],
	);

WPCS Compatibility

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>