sllh/php-cs-fixer-styleci-bridge
composer require --dev sllh/php-cs-fixer-styleci-bridge
.styleci.yml exists in your project root (required for config generation).
Example minimal config:
presets: [styleci]
rules:
braces: ~
linebreak_after_opening_tag: true
php artisan cs:generate):
// app/Console/Commands/GenerateCsFixerConfig.php
use Sllh\PhpCsFixerStyleciBridge\StyleciToPhpCsFixer;
public function handle()
{
$styleciConfig = include __DIR__.'/../../.styleci.yml';
$phpCsFixerConfig = StyleciToPhpCsFixer::convert($styleciConfig);
file_put_contents(base_path('.php-cs-fixer.dist.php'), '<?php return '.var_export($phpCsFixerConfig, true).';');
}
vendor/bin/php-cs-fixer fix
Use this package to eliminate duplicate config maintenance between StyleCI (for CI/CD) and PHP-CS-Fixer (for local development). Ideal for teams already using StyleCI but needing local fixes.
CI/CD Pipeline:
.styleci.yml to version control..php-cs-fixer.dist.php before running tests or fixes.- name: Generate PHP-CS-Fixer config
run: php artisan cs:generate
- name: Run PHP-CS-Fixer
run: vendor/bin/php-cs-fixer fix --diff --dry-run
Local Development:
{
"scripts": {
"post-install-cmd": [
"php artisan cs:generate"
]
}
}
Custom Rules Handling:
// app/Providers/AppServiceProvider.php
use Sllh\PhpCsFixerStyleciBridge\StyleciToPhpCsFixer;
public function boot()
{
StyleciToPhpCsFixer::addCustomRule('custom_rule', function ($value) {
return ['CustomRule' => ['option' => $value]];
});
}
$this->app->singleton('styleci-converter', function ($app) {
return new StyleciToPhpCsFixer();
});
AppServiceProvider:
Artisan::register(new \App\Console\Commands\GenerateCsFixerConfig());
PHP-CS-Fixer v2 Incompatibility:
v1.x in composer.json:
"require-dev": {
"php-cs-fixer": "^1.20"
}
Missing Rule Mappings:
align_double_arrow) have no direct PHP-CS-Fixer equivalent.Preset Conflicts:
styleci) may not align with PHP-CS-Fixer presets.$config = StyleciToPhpCsFixer::convert($styleciConfig);
$config['rules']['array_syntax'] = ['syntax' => 'short'];
$config = StyleciToPhpCsFixer::convert($styleciConfig);
var_dump($config);
--allow-risky=yes with PHP-CS-Fixer v1 to bypass warnings:
vendor/bin/php-cs-fixer fix --allow-risky=yes
StyleciToPhpCsFixer::addCustomRule('phpdoc_align', function ($value) {
return ['phpdoc_align' => ['align' => $value]];
});
$config = StyleciToPhpCsFixer::convert($styleciConfig);
$config['finder']->exclude(['vendor/', 'storage/']);
$cacheKey = 'php-cs-fixer-config';
$config = Cache::remember($cacheKey, now()->addHours(1), function () {
return StyleciToPhpCsFixer::convert($styleciConfig);
});
.styleci.yml must be exact (2 spaces). Use a linter like yamllint to validate.~ for "disabled" (e.g., braces: ~), but PHP-CS-Fixer expects false. The package handles this, but verify with:
var_dump(StyleciToPhpCsFixer::convert(['rules' => ['braces' => '~']]));
How can I help you explore Laravel packages today?