Installation
composer require --dev sllh/styleci-fixers
Note: This package is a dependency for sllh/php-cs-fixer-styleci-bridge. Use that package instead for direct integration.
First Use Case
php-cs-fixer-styleci-bridge, configure it to load StyleCI rules via this package’s generated fixers.php-cs-fixer.dist.php):
use Sllh\StyleCiFixer\StyleCiFixer;
$finder = PhpCsFixer\Finder::create()->in(__DIR__.'/../src');
$styleCiFixer = new StyleCiFixer();
return (new PhpCsFixer\Config())
->setRules($styleCiFixer->getRules())
->setFinder($finder);
Bridge-Based Workflow
php-cs-fixer-styleci-bridge as the primary tool, leveraging this package’s fixers under the hood.- name: Run PHP-CS-Fixer
run: vendor/bin/php-cs-fixer fix --config=php-cs-fixer.dist.php
Dynamic Rule Loading
.styleci.yml file) and apply them via the bridge:
$styleCiFixer = new StyleCiFixer();
$rules = $styleCiFixer->loadFromStyleCiConfig(__DIR__.'/../.styleci.yml');
Tag-Based Filtering
@risky):
$styleCiFixer->setTags(['risky', 'modern']);
// app/Console/Commands/FixStyleCi.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Sllh\StyleCiFixer\StyleCiFixer;
class FixStyleCi extends Command
{
protected $signature = 'styleci:fix';
protected $description = 'Fix files using StyleCI rules';
public function handle()
{
$finder = PhpCsFixer\Finder::create()->in(base_path('app'));
$styleCiFixer = new StyleCiFixer();
$config = (new PhpCsFixer\Config())
->setRules($styleCiFixer->getRules())
->setFinder($finder);
(new PhpCsFixer\Cli\Application())
->run(new \Symfony\Component\Console\Input\ArrayInput([]), $config);
}
}
Register it in app/Console/Kernel.php:
protected $commands = [
Commands\FixStyleCi::class,
];
Deprecated Package
php-cs-fixer-styleci-bridge directly for production.Rule Conflicts
@risky fixers) may break functionality. Test thoroughly:
vendor/bin/php-cs-fixer fix --dry-run --config=php-cs-fixer.dist.php
Configuration Overrides
.php-cs-fixer.dist.php over .styleci.yml. Explicitly merge rules if needed:
$rules = array_merge(
$styleCiFixer->getRules(),
['array_syntax' => ['syntax' => 'short']] // Override
);
print_r($styleCiFixer->getRules());
.styleci.yml match the bridge’s supported tags (check StyleCI SDK).Custom Rule Merging Extend the bridge to merge additional rules:
$styleCiFixer->setRules(array_merge(
$styleCiFixer->getRules(),
['no_unused_imports' => true]
));
CI-Specific Configs Use environment variables to toggle rules in CI:
$rules = $styleCiFixer->getRules();
if (app()->environment('ci')) {
$rules['phpdoc_align'] = false; // Disable in CI
}
Parallel Processing For large codebases, use PHP-CS-Fixer’s parallel mode:
vendor/bin/php-cs-fixer fix --parallel
How can I help you explore Laravel packages today?