Skip to content

Commit 9c6695b

Browse files
committed
Docs: Add another suggested fixer to README
1 parent de6841d commit 9c6695b

5 files changed

+24
-15
lines changed

README.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ Now you will be able to run the fix using `composer analyze` and execute automat
6060
### Add custom checks or override default settings
6161

6262
On top of the default code-style rules, you are free to add any rules from [PHP-CS-Fixer] or [PHP_CodeSniffer].
63-
If needed, you can also override some default settings.
63+
If needed, you can also override any default settings.
64+
65+
Below find examples of some more opinionated checks you may want to add depending on your needs:
6466

6567
```php
6668
<?php declare(strict_types=1);
@@ -76,10 +78,20 @@ return ECSConfig::configure()
7678
__DIR__ . '/vendor/lmc/coding-standard/ecs.php',
7779
]
7880
)
79-
// Enforce line-length to 120 characters
81+
->withRules(
82+
[
83+
// PHPUnit attributes must be used over their respective PHPDoc-based annotations. (Use with PHPUnit 10+.)
84+
PhpUnitAttributesFixer::class,
85+
// Single-line comments must have proper spacing.
86+
SingleLineCommentSpacingFixer::class,
87+
]
88+
)
89+
// Enforce line-length to 120 characters.
8090
->withConfiguredRule(LineLengthSniff::class, ['absoluteLineLimit' => 120])
81-
// Tests must have @test annotation
82-
->withConfiguredRule(PhpUnitTestAnnotationFixer::class, ['style' => 'annotation']);
91+
// Tests must have @test annotation.
92+
->withConfiguredRule(PhpUnitTestAnnotationFixer::class, ['style' => 'annotation'])
93+
// Specify elements separation.
94+
->withConfiguredRule(ClassAttributesSeparationFixer::class, ['elements' => ['const' => 'none', 'method' => 'one', 'property' => 'none']])
8395
/* (...) */
8496
```
8597

ecs-internal.php

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php declare(strict_types=1);
22

33
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
4+
use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer;
45
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer;
56
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
67
use Symplify\EasyCodingStandard\Config\ECSConfig;
@@ -21,6 +22,10 @@
2122
LineLengthFixer::class,
2223
['line_length' => 120, 'break_long_lines' => true, 'inline_short_lines' => false],
2324
)
25+
->withConfiguredRule(
26+
ClassAttributesSeparationFixer::class,
27+
['elements' => ['const' => 'none', 'method' => 'one', 'property' => 'none']],
28+
)
2429
->withSkip(
2530
[
2631
ForbiddenFunctionsSniff::class => ['tests/Integration/CodingStandardTest.php'],

src/Sniffs/Naming/ClassNameSuffixByParentSniff.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,10 @@
3535

3636
final class ClassNameSuffixByParentSniff implements Sniff
3737
{
38-
/**
39-
* @var string
40-
*/
38+
/** @var string */
4139
private const ERROR_MESSAGE = 'Class "%s" should have suffix "%s" by parent class/interface';
4240

43-
/**
44-
* @var string[]
45-
*/
41+
/** @var string[] */
4642
public array $defaultParentClassToSuffixMap = [
4743
'Command',
4844
'Controller',
@@ -56,9 +52,7 @@ final class ClassNameSuffixByParentSniff implements Sniff
5652
'Handler',
5753
];
5854

59-
/**
60-
* @var string[]
61-
*/
55+
/** @var string[] */
6256
public array $extraParentTypesToSuffixes = [];
6357

6458
/**

src/Sniffs/Naming/InterfaceNameSniff.php

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ final class InterfaceNameSniff implements Sniff
3939
private const ERROR_MESSAGE = 'Interface should have suffix "Interface".';
4040

4141
private int $position;
42-
4342
private File $file;
4443

4544
/**

src/Sniffs/Naming/TraitNameSniff.php

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ final class TraitNameSniff implements Sniff
3939
private const ERROR_MESSAGE = 'Trait should have suffix "Trait".';
4040

4141
private int $position;
42-
4342
private File $file;
4443

4544
/**

0 commit comments

Comments
 (0)