interaction-design-foundation / coding-standard
IxDF coding standard: PHP_CodeSniffer rules and shared PHP-CS-Fixer configuration.
Package info
github.com/InteractionDesignFoundation/coding-standard
Type:phpcodesniffer-standard
pkg:composer/interaction-design-foundation/coding-standard
Requires
- php: ^8.4
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- friendsofphp/php-cs-fixer: ^3.89
- slevomat/coding-standard: ^8.29
- squizlabs/php_codesniffer: ^4.0
Requires (Dev)
- phpunit/phpunit: ^12.4
- rector/rector: ^2.5
- vimeo/psalm: ^6.16
README
An opinionated coding standard for PHP and Laravel projects, built on PER-CS 3. Focuses on:
- High signal-to-noise ratio (concise but informative PHPDoc, e.g. array shapes)
- Strict, explicit code:
strict_types, strict comparisons, final by default, no magic - Harmony with static analysis tools (PHPStan, Psalm, Rector, etc.)
- Auto-fixing over reporting (violations are not only reported but also fixed automatically, when possible)
- PHP and Laravel best practices (enforced, not just suggested)
Two tools, two roles, meant to run together:
- PHP-CS-Fixer (primary): fast auto-formatting and modernization rules.
- PHP_CodeSniffer (supplementary): structural and semantic checks PHP-CS-Fixer cannot express (complexity, Laravel conventions, naming).
Tip
This repository is a part of the IxDF toolchain for PHP: Rector ➝ Coding Standard Fixers ➝ PHPStan + Psalm.
1. Installation
composer require --dev interaction-design-foundation/coding-standard
2. Configuration
PHP-CS-Fixer
Primary formatter.
Create .php-cs-fixer.php in your project root:
<?php declare(strict_types=1); use IxDFCodingStandard\PhpCsFixer\Config; // @see https://mlocati.github.io/php-cs-fixer-configurator/ for ruleOverrides options. return Config::create(__DIR__, ruleOverrides: []);
Customization (optional)
Config::create() ships a sensible default Finder and enables parallel runs, risky rules, and caching.
You can customize it by using your Finder instance and by overriding individual rules:
use PhpCsFixer\Finder; $finder = Finder::create()->in(__DIR__)->name('*.php'); // Override individual rules, your own Finder and use your cache path return Config::create(__DIR__, finder: $finder, ruleOverrides: [ 'final_class' => true, ])->setCacheFile('./.cache/.php-cs-fixer.cache');
Need only the rule array (e.g. to compose your own config)?
$rules = \IxDFCodingStandard\PhpCsFixer\Rules::get();
Run it:
vendor/bin/php-cs-fixer fix
PHP_CodeSniffer
Supplementary (optional) formatter.
Create phpcs.xml in your project root:
<?xml version="1.0"?> <ruleset name="My Coding Standard"> <file>app</file> <file>config</file> <file>database</file> <file>routes</file> <file>tests</file> <rule ref="IxDFCodingStandard"/> </ruleset>
On top of the Generic, PSR and Slevomat rulesets, IxDFCodingStandard ships its own sniffs.
Some run by default; some are opt-in. See docs/README.md for the full list and configuration.
Run it:
vendor/bin/phpcbf # fix vendor/bin/phpcs # check (dry-run)
Composer scripts (recommended)
Wire both tools into composer.json so the whole team runs them the same way:
composer cs
cs fixes files in place. Edit composer.json:
{
"scripts": {
"cs": ["@php-cs-fixer", "@phpcbf"],
"phpcbf": "phpcbf -p",
"phpcs": "phpcs -p -s --report-full --report-summary",
"php-cs-fixer": "php-cs-fixer fix --no-interaction --ansi --quiet"
}
}
3. Continuous integration
Run the fixer in CI and commit the result back, so the branch is always formatted without blocking the build.
This repository dogfoods that pattern; copy its workflow as a starting point: .github/workflows/coding-standard.yml.