Skip to content

Basic Usage

Terminal window
composer require cline/coding-standard --dev

The recommended way to use this package is through EasyCodingStandard (ECS), which wraps PHP-CS-Fixer with parallel processing support.

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.

<?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,
],
);
Terminal window
# Check for issues
vendor/bin/ecs check
# Fix issues
vendor/bin/ecs check --fix

For automated code upgrades and refactoring, use the Rector factory.

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'],
);
<?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
);
Terminal window
# Preview changes (dry-run)
vendor/bin/rector --dry-run
# Apply changes
vendor/bin/rector

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());

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:

Terminal window
composer lint # Fix style issues
composer refactor # Apply refactorings
composer test:lint # Check style without fixing
composer test:refactor # Preview refactorings

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.

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.