An opinionated coding standard for PHP/Laravel projects. Provides two independent tools — use either one or both together:
- PHP_CodeSniffer — custom sniffs for strict types and Laravel conventions
- PHP-CS-Fixer — shared config with 80+ rules based on PER-CS 3.0
composer require --dev interaction-design-foundation/coding-standardCreate phpcs.xml in your project root:
<?xml version="1.0"?>
<ruleset name="My Coding Standard">
<rule ref="IxDFCodingStandard"/>
<file>app</file>
<file>config</file>
<file>database</file>
<file>routes</file>
<file>tests</file>
</ruleset>Create .php-cs-fixer.php in your project root:
<?php declare(strict_types=1);
use IxDFCodingStandard\PhpCsFixer\Config;
return Config::create(__DIR__);With rule overrides:
return Config::create(__DIR__, ruleOverrides: [
'final_public_method_for_abstract_class' => false,
]);With a custom Finder:
use IxDFCodingStandard\PhpCsFixer\Config;
use PhpCsFixer\Finder;
$finder = Finder::create()->in(__DIR__)->name('*.php');
return Config::create(__DIR__, finder: $finder);If you only need the rules array:
$rules = \IxDFCodingStandard\PhpCsFixer\Rules::get();vendor/bin/phpcs # check with PHP_CodeSniffer
vendor/bin/phpcbf # fix with PHP_CodeSniffer
vendor/bin/php-cs-fixer fix --dry-run --diff # check with PHP-CS-Fixer
vendor/bin/php-cs-fixer fix # fix with PHP-CS-FixerAdd to your composer.json:
"scripts": {
"cs": "@cs:fix",
"cs:check": ["@php-cs-fixer:dry", "@phpcs"],
"cs:fix": ["@php-cs-fixer", "@phpcbf"],
"phpcs": "phpcs -p -s --colors --report-full --report-summary",
"phpcbf": "phpcbf -p --colors",
"php-cs-fixer": "php-cs-fixer fix --no-interaction --ansi --quiet",
"php-cs-fixer:dry": "php-cs-fixer fix --no-interaction --ansi --verbose --dry-run"
}Then run:
composer cs:check # run both tools in check mode
composer cs:fix # run both tools in fix mode
composer phpcs # PHP_CodeSniffer only
composer php-cs-fixer # PHP-CS-Fixer only