File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed
tests/Integration/Fixtures Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 55
55
use PhpCsFixer \Fixer \CastNotation \ShortScalarCastFixer ;
56
56
use PhpCsFixer \Fixer \ClassNotation \ClassAttributesSeparationFixer ;
57
57
use PhpCsFixer \Fixer \ClassNotation \NoBlankLinesAfterClassOpeningFixer ;
58
+ use PhpCsFixer \Fixer \ClassNotation \OrderedClassElementsFixer ;
58
59
use PhpCsFixer \Fixer \ClassNotation \SelfAccessorFixer ;
59
60
use PhpCsFixer \Fixer \ClassNotation \SingleTraitInsertPerStatementFixer ;
60
61
use PhpCsFixer \Fixer \ClassNotation \VisibilityRequiredFixer ;
519
520
'use_trait ' ,
520
521
],
521
522
])
523
+ // Elements of classes/interfaces/traits/enums should be in the defined order
524
+ ->withConfiguredRule (
525
+ OrderedClassElementsFixer::class,
526
+ [
527
+ 'order ' => [
528
+ 'use_trait ' ,
529
+ 'case ' , // enum values should be before other elements
530
+ 'constant ' ,
531
+ 'property ' ,
532
+ 'construct ' ,
533
+ 'destruct ' ,
534
+ 'magic ' ,
535
+ 'phpunit ' , // phpunit special methods like setUp should be before test methods
536
+ 'method ' ,
537
+ ],
538
+ ],
539
+ )
522
540
->withSkip ([
523
541
// We allow empty catch statements (but they must have comment - see EmptyCatchCommentSniff)
524
542
EmptyStatementSniff::class . '.DetectedCatch ' => null ,
Original file line number Diff line number Diff line change @@ -4,8 +4,13 @@ use Bar\Foo; // NoUnneededImportAliasFixer
4
4
5
5
class Basic
6
6
{
7
+ use SomeUsefulTrait; // OrderedClassElementsFixer
7
8
public const FOO = 'foo ' ; // ClassAttributesSeparationFixer
8
9
10
+ public const MY_PUBLIC_CONST = 333 ; // OrderedClassElementsFixer
11
+
12
+ protected int $ myProperty = 666 ; // OrderedClassElementsFixer
13
+
9
14
public function isEqual ($ a , ?string $ b ): ?bool // VisibilityRequiredFixer, CompactNullableTypeDeclarationFixer
10
15
{
11
16
// TrimArraySpacesFixer
Original file line number Diff line number Diff line change @@ -29,6 +29,8 @@ class Basic
29
29
return false ; // BlankLineBeforeStatementFixer
30
30
}
31
31
32
+ public const MY_PUBLIC_CONST = 333 ; // OrderedClassElementsFixer
33
+
32
34
public function fooBar (mixed $ foo ): mixed
33
35
{
34
36
// PhpdocToCommentFixer
@@ -47,4 +49,8 @@ class Basic
47
49
// TernaryToElvisOperatorFixer
48
50
return ($ foo ? $ foo : 'not true ' );
49
51
}
52
+
53
+ protected int $ myProperty = 666 ; // OrderedClassElementsFixer
54
+
55
+ use SomeUsefulTrait; // OrderedClassElementsFixer
50
56
}
You can’t perform that action at this time.
0 commit comments