imbo/imbo-coding-standard
PHP-CS-Fixer ruleset for Imbo and related PHP projects. Install as a dev dependency, add a .php-cs-fixer.dist.php config, and run php-cs-fixer check/fix locally or in GitHub Actions/Composer scripts to enforce consistent code style.
Install Dependencies
composer require --dev imbo/imbo-coding-standard ^3.0 friendsofphp/php-cs-fixer
Create Config File
Place .php-cs-fixer.dist.php in your project root with:
<?php declare(strict_types=1);
require 'vendor/autoload.php';
$finder = new PhpCsFixer\Finder();
$config = new Imbo\CodingStandard\Config();
return $config
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setFinder($finder->in(__DIR__)->append([__FILE__]));
First Use Case Run a dry check to preview violations:
vendor/bin/php-cs-fixer check --diff
Local Development
{
"scripts": {
"cs": "vendor/bin/php-cs-fixer check --diff",
"cs:fix": "vendor/bin/php-cs-fixer fix --diff"
}
}
composer cs:fix
CI/CD Pipeline
- name: Check coding standard
run: vendor/bin/php-cs-fixer check --diff
--diff.Team Onboarding
CONTRIBUTING.md:
## Code Style
Run `composer cs` to validate changes against Imbo’s PHP-CS-Fixer rules.
Focused Fixing
$finder->in(__DIR__)
->exclude('tests')
->append(['config/', 'routes/']);
Custom Rules
no_unused_imports):
$config->setRules([
'@Imbo' => true,
'no_unused_imports' => true,
]);
Pre-Commit Hooks
php-cs-fixer with tools like Husky:
composer cs -- --allow-risky=yes
Parallel Processing
ParallelConfigFactory::detect() is set (default in the config).Rule Conflicts
$config->setRules([
'@Imbo' => true,
'array_syntax' => ['syntax' => 'short'], // Force short array syntax
]);
CI Failures
--diff output.--diff in CI for strict enforcement:
run: vendor/bin/php-cs-fixer check
Verbose Output
vendor/bin/php-cs-fixer fix --verbose --dry-run
Rule Whitelisting
$finder->notPath('legacy/');
Custom Rule Sets
vendor/bin/php-cs-fixer fix --rules=@Imbo --dry-run --verbose
Add Custom Rules
@Symfony):
$config->setRules([
'@Imbo' => true,
'@Symfony' => true,
]);
Cache Configuration
$config->setCacheFile(__DIR__ . '/.php-cs-fixer.cache');
Path Exclusions
$finder->exclude([
'vendor/',
'bootstrap/cache/',
]);
How can I help you explore Laravel packages today?