Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork86
The Easiest way to add coding standard to your PHP project
License
easy-coding-standard/easy-coding-standard
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- Install onany PHP 7.2-PHP 8.4 project with any dependencies
- Blazing fast with parallel run out of the box
- UsePHP_CodeSniffer or PHP-CS-Fixer - anything you like
- Useprepared sets andPHP CS Fixer sets to save time
composer require symplify/easy-coding-standard --dev
vendor/bin/ecs
On the first run, ECS createsecs.php
config file with directories and first rule to kick off.
Then you can run again to see the suggested diffs:
vendor/bin/ecs
To actuallyfix your code, add--fix
:
vendor/bin/ecs --fix
That's it!
Most of the time, you'll be happy with the default configuration. The most relevant part is configuring paths, checkers and sets:
usePhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;usePhpCsFixer\Fixer\ListNotation\ListSyntaxFixer;useSymplify\EasyCodingStandard\Config\ECSConfig;return ECSConfig::configure() ->withPaths([__DIR__ .'/src',__DIR__ .'/tests']) ->withConfiguredRule( ArraySyntaxFixer::class, ['syntax' =>'long'] ) ->withRules([ ListSyntaxFixer::class, ]) ->withPreparedSets(psr12:true);
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:
useSymplify\EasyCodingStandard\Config\ECSConfig;return ECSConfig::configure() ->withPaths([__DIR__ .'/src',__DIR__ .'/tests']) ->withRootFiles();
Do you want to include one of 44 sets fromphp-cs-fixer?
You can:
useSymplify\EasyCodingStandard\Config\ECSConfig;return ECSConfig::configure() ->withPaths([__DIR__ .'/src',__DIR__ .'/tests']) ->withPhpCsFixerSets(perCS20:true, doctrineAnnotation:true);
Love the sets of rules, but want to skip single rule or some files?
useSymplify\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', ]);
You probably won't use these, but they can give you more control over the internal process:
useSymplify\EasyCodingStandard\Config\ECSConfig;useSymplify\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.
Do you use ECS across variety of project? Do you want to run them always the same way in each of those project? Let's make use ofComposer scripts
This command adds 2 handy scripts to yourcomposer.json
:
vendor/bin/ecs scripts
Run them always the same way - to check the code:
composer check-cs
To apply fixes, run:
composer fix-cs
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.junit
: JUnit format to be used in different CI environments.checkstyle
: Useful for Github Action Reports.gitlab
: For Gitlab code quality reports or Code Climate tooling.
For information on how each of these behave, refer to their respectiveimplementations.
vendor/bin/ecs --clear-cache
vendor/bin/ecs list-checkers
Do you look for json format?
vendor/bin/ecs list-checkers --output-format json
Can I Use My.editorconfig
?
Mostly! By usingwithEditorConfig()
, ECS will automatically discoverthe.editorconfig
file in the project's root directory. It will use anyrules under[*]
or[*.php]
(the latter taking priority) and respect thesettings for:
indent_style
end_of_line
max_line_length
trim_trailing_whitespace
insert_final_newline
quote_type
- Only
single
andauto
are respected. - Warning: this is a proposed field, but not fully standard.
- Only
These settings will take precedence over similar rules configured through setslike PSR12, to avoid conflicting with other tooling using your.editorconfig
.
Unfortunately, not all settings are currently respected, but PRs are alwayswelcome!
Do you use another tool and want to migrate? It's pretty straightforward - here is "how to":
- forPHP_CodeSniffer
- andPHP CS Fixer.
About
The Easiest way to add coding standard to your PHP project
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.