Skip to content

Commit 1dad965

Browse files
committed
Updated ECS to commit 4ceffb16a07f40f0d107ad4e4a6e230b1e13dea3
1 parent 96294d6 commit 1dad965

969 files changed

Lines changed: 4360 additions & 4112 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 249 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,249 @@
1-
override
1+
# The Easiest way to use Coding Standard
2+
3+
[![Downloads total](https://img.shields.io/packagist/dt/symplify/easy-coding-standard.svg?style=flat-square)](https://packagist.org/packages/symplify/easy-coding-standard/stats)
4+
5+
Easy Coding Standard (ECS) is a single tool that runs [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) and [PHP-CS-Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) rules together, configured through one simple PHP file.
6+
7+
> [!NOTE]
8+
> This is the **deployed** package. Development happens in the [symplify/easy-coding-standard](https://github.com/easy-coding-standard/easy-coding-standard) repository - report issues and send pull requests there.
9+
10+
<br>
11+
12+
## Killer Features
13+
14+
- Install on **any PHP 7.2-PHP 8.5** project with any dependencies
15+
- Blazing fast with parallel run out of the box
16+
- Use [PHP_CodeSniffer or PHP-CS-Fixer](https://tomasvotruba.com/blog/2017/05/03/combine-power-of-php-code-sniffer-and-php-cs-fixer-in-3-lines/) - anything you like
17+
- Use **prepared sets** and [PHP CS Fixer sets](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/index.rst) to save time
18+
19+
<br>
20+
21+
## Install
22+
23+
```bash
24+
composer require symplify/easy-coding-standard --dev
25+
```
26+
27+
<br>
28+
29+
## Usage
30+
31+
```bash
32+
vendor/bin/ecs
33+
```
34+
35+
On the first run, ECS creates `ecs.php` config file with directories and first rule to kick off.
36+
37+
Then you can run again to see the suggested diffs:
38+
39+
```bash
40+
vendor/bin/ecs
41+
```
42+
43+
To actually **fix your code**, add `--fix`:
44+
45+
```bash
46+
vendor/bin/ecs --fix
47+
```
48+
49+
That's it!
50+
51+
<br>
52+
53+
## Configure
54+
55+
Most of the time, you'll be happy with the default configuration. The most relevant part is configuring paths, checkers and sets:
56+
57+
```php
58+
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
59+
use PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer;
60+
use Symplify\EasyCodingStandard\Config\ECSConfig;
61+
62+
return ECSConfig::configure()
63+
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
64+
65+
// start slow with sole rules
66+
->withRules([
67+
ListSyntaxFixer::class,
68+
])
69+
->withConfiguredRule(
70+
ArraySyntaxFixer::class,
71+
['syntax' => 'long']
72+
)
73+
74+
// apply full set
75+
->withPreparedSets(psr12: true);
76+
```
77+
78+
<br>
79+
80+
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:
81+
82+
```php
83+
use Symplify\EasyCodingStandard\Config\ECSConfig;
84+
85+
return ECSConfig::configure()
86+
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
87+
->withRootFiles();
88+
```
89+
90+
<br>
91+
92+
Do you want to include one of sets from [php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/index.rst)?
93+
94+
You can:
95+
96+
```php
97+
use Symplify\EasyCodingStandard\Config\ECSConfig;
98+
99+
return ECSConfig::configure()
100+
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
101+
->withPhpCsFixerSets(perCS20: true, doctrineAnnotation: true);
102+
```
103+
104+
<br>
105+
106+
### Gradual Adoption with Levels
107+
108+
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:
109+
110+
```php
111+
use Symplify\EasyCodingStandard\Config\ECSConfig;
112+
113+
return ECSConfig::configure()
114+
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
115+
->withSpacesLevel(0)
116+
->withArrayLevel(0)
117+
->withControlStructuresLevel(0)
118+
->withDocblockLevel(0);
119+
```
120+
121+
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.
122+
123+
<br>
124+
125+
### How to Skip Files/Rules?
126+
127+
Love the sets of rules, but want to skip single rule or some files?
128+
129+
```php
130+
use Symplify\EasyCodingStandard\Config\ECSConfig;
131+
132+
return ECSConfig::configure()
133+
->withSkip([
134+
// skip single rule
135+
ArraySyntaxFixer::class,
136+
137+
// skip single rule in specific paths
138+
ArraySyntaxFixer::class => [
139+
__DIR__ . '/src/ValueObject/',
140+
],
141+
142+
// skip directory by absolute or * mask
143+
__DIR__ . '/src/Migrations',
144+
145+
// skip directories by mask
146+
__DIR__ . '/src/*/Legacy',
147+
]);
148+
```
149+
150+
<br>
151+
152+
### Less Common Options
153+
154+
You probably won't use these, but they can give you more control over the internal process:
155+
156+
```php
157+
use Symplify\EasyCodingStandard\Config\ECSConfig;
158+
use Symplify\EasyCodingStandard\ValueObject\Option;
159+
160+
return ECSConfig::configure()
161+
// file extensions to scan
162+
->withFileExtensions(['php'])
163+
164+
// configure cache paths and namespace - useful e.g. Gitlab CI caching, where getcwd() produces always different path
165+
->withCache(
166+
directory: sys_get_temp_dir() . '/_changed_files_detector_tests',
167+
namespace: getcwd() // normalized to directory separator
168+
)
169+
170+
// print contents with specific indent rules
171+
->withSpacing(indentation: Option::INDENTATION_SPACES, lineEnding: PHP_EOL)
172+
173+
// modify parallel run
174+
->withParallel(timeoutSeconds: 120, maxNumberOfProcess: 32, jobSize: 20);
175+
```
176+
177+
Mentioned values are default ones.
178+
179+
<br>
180+
181+
### Controlling Output Format
182+
183+
You may want to use ECS to generate reports for third-party tooling.
184+
185+
We currently provide formatters for:
186+
187+
- `console`: Human-oriented printing à la PHP CS Fixer.
188+
- `json`: A custom JSON blob for arbitrary tooling.
189+
- `junit`: JUnit format to be used in different CI environments.
190+
- `checkstyle`: Useful for Github Action Reports.
191+
- `gitlab`: For Gitlab code quality reports or Code Climate tooling.
192+
193+
You can use the output format option as below
194+
195+
```bash
196+
vendor/bin/ecs --output-format=checkstyle
197+
```
198+
199+
<br>
200+
201+
## FAQ
202+
203+
### How do I clear cache?
204+
205+
```bash
206+
vendor/bin/ecs --clear-cache
207+
```
208+
209+
### How can I see all used rules?
210+
211+
```bash
212+
vendor/bin/ecs list-checkers
213+
```
214+
215+
Do you look for json format?
216+
217+
```bash
218+
vendor/bin/ecs list-checkers --output-format json
219+
```
220+
221+
<br>
222+
223+
### Can I Use My [`.editorconfig`](https://editorconfig.org/)?
224+
225+
Mostly! By using `->withEditorConfig()` in `ecs.php`, ECS will automatically discover
226+
the `.editorconfig` file in the project's root directory. It will use any
227+
rules under `[*]` or `[*.php]` (the latter taking priority) and respect the
228+
settings for:
229+
230+
- `indent_style`
231+
- `end_of_line`
232+
- `max_line_length`
233+
- `trim_trailing_whitespace`
234+
- `insert_final_newline`
235+
- [`quote_type`](https://github.com/jednano/codepainter#quote_type-single-double-auto)
236+
- Only `single` and `auto` are respected.
237+
- Warning: this is a proposed field, but not fully standard.
238+
239+
These settings will take precedence over similar rules configured through sets
240+
like PSR12, to avoid conflicting with other tooling using your `.editorconfig`.
241+
242+
<br>
243+
244+
## How to Migrate from another coding standard tool?
245+
246+
Do you use another tool and want to migrate? It's pretty straightforward - here is "how to":
247+
248+
* for [PHP_CodeSniffer](https://tomasvotruba.com/blog/2018/06/04/how-to-migrate-from-php-code-sniffer-to-easy-coding-standard)
249+
* and [PHP CS Fixer](https://tomasvotruba.com/blog/2018/06/07/how-to-migrate-from-php-cs-fixer-to-easy-coding-standard).

bin/ecs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env php
22
<?php
3-
namespace ECSPrefix202605;
3+
namespace ECSPrefix202606;
44

55
require __DIR__ . '/ecs.php';

bin/ecs.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

33
declare (strict_types=1);
4-
namespace ECSPrefix202605;
4+
namespace ECSPrefix202606;
55

66
// decoupled in own "*.php" file, so ECS, Rector and PHPStan works out of the box here
77
use PHP_CodeSniffer\Util\Tokens;
8-
use ECSPrefix202605\Symfony\Component\Console\Command\Command;
9-
use ECSPrefix202605\Symfony\Component\Console\Input\ArgvInput;
8+
use ECSPrefix202606\Symfony\Component\Console\Command\Command;
9+
use ECSPrefix202606\Symfony\Component\Console\Input\ArgvInput;
1010
use Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication;
1111
use Symplify\EasyCodingStandard\Console\Style\SymfonyStyleFactory;
1212
use Symplify\EasyCodingStandard\DependencyInjection\EasyCodingStandardContainerFactory;
@@ -119,7 +119,7 @@ public function loadIfNotLoadedYet(string $file): void
119119
/**
120120
* Inspired by https://github.com/rectorphp/rector/pull/2373/files#diff-0fc04a2bb7928cac4ae339d5a8bf67f3
121121
*/
122-
\class_alias('ECSPrefix202605\ECSAutoloadIncluder', 'ECSAutoloadIncluder', \false);
122+
\class_alias('ECSPrefix202606\ECSAutoloadIncluder', 'ECSAutoloadIncluder', \false);
123123
try {
124124
$input = new ArgvInput();
125125
$ecsContainerFactory = new EasyCodingStandardContainerFactory();

bin/generate-php-cs-fixer-tests.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
<?php
22

33
declare (strict_types=1);
4-
namespace ECSPrefix202605;
4+
namespace ECSPrefix202606;
55

66
use PhpCsFixer\RuleSet\RuleSets;
7-
use ECSPrefix202605\PhpParser\Modifiers;
8-
use ECSPrefix202605\PhpParser\Node\Expr\ArrayDimFetch;
9-
use ECSPrefix202605\PhpParser\Node\Expr\Assign;
10-
use ECSPrefix202605\PhpParser\Node\Expr\ConstFetch;
11-
use ECSPrefix202605\PhpParser\Node\Expr\PropertyFetch;
12-
use ECSPrefix202605\PhpParser\Node\Expr\Variable;
13-
use ECSPrefix202605\PhpParser\Node\Identifier;
14-
use ECSPrefix202605\PhpParser\Node\Name;
15-
use ECSPrefix202605\PhpParser\Node\Param;
16-
use ECSPrefix202605\PhpParser\Node\Scalar\String_;
17-
use ECSPrefix202605\PhpParser\Node\Stmt\ClassMethod;
18-
use ECSPrefix202605\PhpParser\Node\Stmt\Expression;
19-
use ECSPrefix202605\PhpParser\Node\Stmt\If_;
20-
use ECSPrefix202605\PhpParser\Node\Stmt\Return_;
21-
use ECSPrefix202605\PhpParser\PrettyPrinter\Standard;
7+
use ECSPrefix202606\PhpParser\Modifiers;
8+
use ECSPrefix202606\PhpParser\Node\Expr\ArrayDimFetch;
9+
use ECSPrefix202606\PhpParser\Node\Expr\Assign;
10+
use ECSPrefix202606\PhpParser\Node\Expr\ConstFetch;
11+
use ECSPrefix202606\PhpParser\Node\Expr\PropertyFetch;
12+
use ECSPrefix202606\PhpParser\Node\Expr\Variable;
13+
use ECSPrefix202606\PhpParser\Node\Identifier;
14+
use ECSPrefix202606\PhpParser\Node\Name;
15+
use ECSPrefix202606\PhpParser\Node\Param;
16+
use ECSPrefix202606\PhpParser\Node\Scalar\String_;
17+
use ECSPrefix202606\PhpParser\Node\Stmt\ClassMethod;
18+
use ECSPrefix202606\PhpParser\Node\Stmt\Expression;
19+
use ECSPrefix202606\PhpParser\Node\Stmt\If_;
20+
use ECSPrefix202606\PhpParser\Node\Stmt\Return_;
21+
use ECSPrefix202606\PhpParser\PrettyPrinter\Standard;
2222
// this helper script generates the withPhpCsFixerSets() method for ECSConfigBuilder class
2323
require __DIR__ . '/../vendor/autoload.php';
2424
$setsDirectory = __DIR__ . '/../vendor/friendsofphp/php-cs-fixer/src/RuleSet/Sets/';

config/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
declare (strict_types=1);
4-
namespace ECSPrefix202605;
4+
namespace ECSPrefix202606;
55

66
use Symplify\EasyCodingStandard\Application\Version\StaticVersionResolver;
77
use Symplify\EasyCodingStandard\Config\ECSConfig;

config/set/clean-code.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
declare (strict_types=1);
4-
namespace ECSPrefix202605;
4+
namespace ECSPrefix202606;
55

66
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
77
use PhpCsFixer\Fixer\ClassNotation\ProtectedToPrivateFixer;

config/set/common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
declare (strict_types=1);
4-
namespace ECSPrefix202605;
4+
namespace ECSPrefix202606;
55

66
use Symplify\EasyCodingStandard\Config\ECSConfig;
77
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

config/set/common/array.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
declare (strict_types=1);
4-
namespace ECSPrefix202605;
4+
namespace ECSPrefix202606;
55

66
use Symplify\EasyCodingStandard\Config\ECSConfig;
77
use Symplify\EasyCodingStandard\Config\Level\ArrayLevel;

config/set/common/comments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
declare (strict_types=1);
4-
namespace ECSPrefix202605;
4+
namespace ECSPrefix202606;
55

66
use PHP_CodeSniffer\Standards\Generic\Sniffs\VersionControl\GitMergeConflictSniff;
77
use Symplify\EasyCodingStandard\Config\ECSConfig;

config/set/common/control-structures.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
declare (strict_types=1);
4-
namespace ECSPrefix202605;
4+
namespace ECSPrefix202606;
55

66
use Symplify\EasyCodingStandard\Config\ECSConfig;
77
use Symplify\EasyCodingStandard\Config\Level\ControlStructuresLevel;

0 commit comments

Comments
 (0)