GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ecsphp/ecs: ECS runs PHP-CS-Fixer and PHP_CodeSniffer as a single, parallel fast tool with zero dependencies. Run on PHP 7.2+

BranchesTags
Open more actions menu

Latest commit

 

History

731 Commits
731 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
bin
bin
 
 
build
build
 
 
config
config
 
 
packages/coding-standard/src
packages/coding-standard/src
 
 
patches
patches
 
 
src
src
 
 
stubs
stubs
 
 
templates
templates
 
 
tests-released
tests-released
 
 
tests
tests
 
 
vendor
vendor
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
CLAUDE.md
CLAUDE.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
bootstrap.php
bootstrap.php
 
 
composer.json
composer.json
 
 
ecs.php
ecs.php
 
 
full_ecs_build.sh
full_ecs_build.sh
 
 
phpstan.neon
phpstan.neon
 
 
phpunit.xml
phpunit.xml
 
 
prefix-code.sh
prefix-code.sh
 
 
preload.php
preload.php
 
 
rector.php
rector.php
 
 
scoper.php
scoper.php
 
 

Repository files navigation

The Easiest and Fastest Coding Standard

Downloads total

Easy Coding Standard (ECS) is a single tool that runs PHP_CodeSniffer and PHP-CS-Fixer rules together, configured through one simple PHP file.

Fixes all of Symfony in 3 seconds. php-cs-fixer and PHP_CodeSniffer take over 2 minutes.

--fix on a fresh clone Symfony src (13,103 files) Laravel src (1,749 files)
ECS --blink 2.9 s 1.0 s
php-cs-fixer 141.6 s 25.8 s
PHP_CodeSniffer 133.7 s 26.7 s

See full benchmark.


Killer Features

  • Blazing fast - fixes all 13,103 files of Symfony in 2.9 s with the bundled Go engine via --blink, 100x faster than the PHP engine (315 s) and 49x faster than php-cs-fixer (141.6 s)
  • Install on any PHP 7.2-PHP 8.5 project with any dependencies
  • Use PHP_CodeSniffer or PHP-CS-Fixer - anything you like
  • Use 14 prepared sets to save time

Install

composer require symplify/easy-coding-standard --dev

Usage

vendor/bin/ecs

The first run creates an ecs.php config with your directories and a first rule. Run it again to see suggested diffs - then add --fix to apply them:

vendor/bin/ecs --fix

Check specific paths instead of the configured ones by passing them as arguments:

vendor/bin/ecs src tests

That's it!


Blazing fast with --blink

ECS bundles a Go engine ("blink") that applies the same rules as the PHP run, across all CPU cores. Pass --blink to use it:

vendor/bin/ecs check --blink          # report
vendor/bin/ecs check --blink --fix    # rewrite in place

When every rule in your ecs.php is covered by the Go engine, a plain vendor/bin/ecs check uses it automatically and falls back to the PHP engine otherwise.

Wall-clock --fix over a fresh clone, each tool with a representative rule set (ECS, --blink and phpcbf run across all cores; php-cs-fixer and Pint run sequentially, as shipped):

engine symfony src (13,103 files) laravel src (1,749 files)
ECS --blink (Go) 2.9 s 1.0 s
ECS (PHP) 315 s 42 s
php-cs-fixer (@PER-CS, @Symfony) 141.6 s 25.8 s
PHP_CodeSniffer (phpcbf, PSR-12) 133.7 s 26.7 s
Laravel Pint (laravel preset) 1,543 s 199 s

Different tools apply different rules, so this compares each at a representative job, not rule for rule. Numbers vary with hardware. The Go engine ships prebuilt for Linux, macOS and Windows, so no Go toolchain is needed.

On symfony/symfony src, php-cs-fixer and Pint also need the rules its @php-cs-fixer-ignore annotations reference (--allow-risky) enabled, or they abort before running.


Configure

Most of the time, you'll be happy with the default configuration. The most relevant part is configuring paths and sets.

Prepared Sets

->withPreparedSets() bundles curated rule sets. Enable the whole common set, or pick single topics:

use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
    ->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
    ->withPreparedSets(
        arrays: true,
        spaces: true,
        namespaces: true,
        docblocks: true,
        controlStructures: true,
        comments: true,
        casing: true,
        cleanup: true,
    );
Set What it covers
arrays array syntax, spacing, trailing commas, indentation
spaces whitespace, operator/type spacing, blank lines
namespaces imports ordering, unused/needless-alias imports
docblocks phpdoc tags, types, alignment, cleanup
controlStructures control flow, casing, operators, class structure
comments comment style, spacing, empty-comment cleanup
casing native function/type, magic method, literal casing
cleanup dead statements, useless returns/casts, unused closure imports

Or enable everything at once with ->withPreparedSets(common: true).

Standalone presets are also available: psr12: true, perCs: true, cleanCode: true (dead code, unused imports, redundant syntax), standaloneLine: true (each constructor param on its own line), and laravel: true (the Laravel Pint ruleset):

use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
    ->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
    ->withPreparedSets(laravel: true);

Single Rules

Prefer to start slow? Pick single rules, and configure them if needed:

use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
    ->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
    ->withRules([
        ListSyntaxFixer::class,
    ])
    ->withConfiguredRule(
        ArraySyntaxFixer::class,
        ['syntax' => 'long']
    );

Check All Root Files

Do you want to check all *.php files in your root (ecs.php, rector.php etc.)? Instead of listing them one by one, use ->withRootFiles() method:

use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
    ->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
    ->withRootFiles();

Gradual Adoption with Levels

Want to adopt a coding standard step by step instead of all at once? Use with*Level() methods to start from the safest rules and raise the level as your codebase catches up:

use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
    ->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
    ->withSpacesLevel(0)
    ->withArrayLevel(0)
    ->withControlStructuresLevel(0)
    ->withDocblockLevel(0);

Each level enables the first N+1 rules from a curated list, ordered from safest to most invasive. Bump the number once your codebase is clean on the current level.


How to Skip Files/Rules?

Love the sets of rules, but want to skip single rule or some files?

use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
    ->withSkip([
        // skip single rule
        ArraySyntaxFixer::class,

        // skip single rule in specific paths
        ArraySyntaxFixer::class => [
            __DIR__ . '/src/ValueObject/',
        ],

        // skip directory by absolute or * mask
        __DIR__ . '/src/Migrations',

        // skip directories by mask
        __DIR__ . '/src/*/Legacy',
    ]);

Less Common Options

You probably won't use these, but they can give you more control over the internal process:

use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Option;

return ECSConfig::configure()
    // file extensions to scan
    ->withFileExtensions(['php'])

    // configure cache paths and namespace - useful e.g. Gitlab CI caching, where getcwd() produces always different path
    ->withCache(
        directory: sys_get_temp_dir() . '/_changed_files_detector_tests',
        namespace: getcwd() // normalized to directory separator
    )

    // print contents with specific indent rules
    ->withSpacing(indentation: Option::INDENTATION_SPACES, lineEnding: PHP_EOL)

    // modify parallel run
    ->withParallel(timeoutSeconds: 120, maxNumberOfProcess: 32, jobSize: 20);

Mentioned values are default ones.


Controlling Output Format

You may want to use ECS to generate reports for third-party tooling.

We currently provide formatters for:

  • console: Human-oriented printing à la PHP CS Fixer.
  • json: A custom JSON blob for arbitrary tooling.

You can use the output format option as below

vendor/bin/ecs --output-format=json

FAQ

How do I clear cache?

vendor/bin/ecs --clear-cache

How can I see all used rules?

vendor/bin/ecs list-checkers

Do you look for json format?

vendor/bin/ecs list-checkers --output-format json

How to Migrate from another coding standard tool?

Do you use another tool and want to migrate? It's pretty straightforward - here is "how to":

  • for PHP_CodeSniffer
  • and PHP CS Fixer.

Note

This is the deployed package. Development happens in the ecs-src repository - report issues and send pull requests there.

About

ECS runs PHP-CS-Fixer and PHP_CodeSniffer as a single, parallel fast tool with zero dependencies. Run on PHP 7.2+

tomasvotruba.com/blog/zen-config-in-ecs

Topics

cicoding-standardcoding-styleparallelphppsr-12

Resources

Readme
MIT license
Activity
Custom properties

Stars

1.6k stars

Watchers

19 watching

Forks

91 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.