Basic Usage
Installation
Section titled “Installation”composer require cline/coding-standard --devEasyCodingStandard (Recommended)
Section titled “EasyCodingStandard (Recommended)”The recommended way to use this package is through EasyCodingStandard (ECS), which wraps PHP-CS-Fixer with parallel processing support.
Quick Setup
Section titled “Quick Setup”Create an ecs.php in your project root:
<?php declare(strict_types=1);
use Cline\CodingStandard\EasyCodingStandard\Factory;
return Factory::create( paths: [__DIR__.'/src', __DIR__.'/tests'],);That’s it! The factory provides sensible defaults using the Standard preset.
With Custom Options
Section titled “With Custom Options”<?php declare(strict_types=1);
use Cline\CodingStandard\EasyCodingStandard\Factory;use Cline\CodingStandard\PhpCsFixer\Preset\Standard;
return Factory::create( paths: [__DIR__.'/src', __DIR__.'/tests'], skip: [ // Skip specific rules for specific paths SomeFixer::class => ['src/Legacy/*'], ], preset: new Standard(), rules: [ // Override or add rules 'single_line_throw' => true, ],);Running ECS
Section titled “Running ECS”# Check for issuesvendor/bin/ecs check
# Fix issuesvendor/bin/ecs check --fixRector (Automated Refactoring)
Section titled “Rector (Automated Refactoring)”For automated code upgrades and refactoring, use the Rector factory.
Quick Setup
Section titled “Quick Setup”Create a rector.php in your project root:
<?php declare(strict_types=1);
use Cline\CodingStandard\Rector\Factory;
return Factory::create( paths: [__DIR__.'/src', __DIR__.'/tests'],);With Custom Options
Section titled “With Custom Options”<?php declare(strict_types=1);
use Cline\CodingStandard\Rector\Factory;
return Factory::create( paths: [__DIR__.'/src', __DIR__.'/tests'], skip: [ // Skip specific rules SomeRector::class => ['src/Legacy/*'], ], withRootFiles: true, // Include root PHP files laravel: true, // Include Laravel-specific rules maxProcesses: 8, // Parallel processing);Running Rector
Section titled “Running Rector”# Preview changes (dry-run)vendor/bin/rector --dry-run
# Apply changesvendor/bin/rectorDirect PHP-CS-Fixer Usage
Section titled “Direct PHP-CS-Fixer Usage”If you prefer using PHP-CS-Fixer directly (without ECS), you can still use the presets:
<?php declare(strict_types=1);
use Cline\CodingStandard\PhpCsFixer\ConfigurationFactory;use Cline\CodingStandard\PhpCsFixer\Preset\Standard;
return ConfigurationFactory::createFromPreset(new Standard());Composer Scripts
Section titled “Composer Scripts”Add convenient scripts to your composer.json:
{ "scripts": { "lint": "vendor/bin/ecs check --fix", "refactor": "rector", "test:lint": "vendor/bin/ecs check", "test:refactor": "rector --dry-run" }}Then run:
composer lint # Fix style issuescomposer refactor # Apply refactoringscomposer test:lint # Check style without fixingcomposer test:refactor # Preview refactoringsAvailable Presets
Section titled “Available Presets”The package includes several presets:
- Standard - Complete rule set for PHP 8.4+ projects (recommended)
- PHPDoc - PHPDoc formatting and standards
- PHPUnit - PHPUnit test formatting
- Ordered - Import and ordering rules
The Standard preset already includes PHPDoc, PHPUnit, and Ordered presets.
Custom Fixers
Section titled “Custom Fixers”This package registers several custom fixers automatically:
- Naming convention fixers (Abstract, Interface, Trait, Exception)
- Import FQCN fixers (new, attributes, static calls, properties)
- Architecture fixers (namespace, author tags, version tags)
- Code quality fixers (duplicate docblocks, readonly classes, variable case)
See Custom Fixers for detailed documentation.