File tree 3 files changed +29
-0
lines changed
tests/Integration/Fixtures
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 ;
517
518
'use_trait ' ,
518
519
],
519
520
])
521
+ // Elements of classes/interfaces/traits/enums should be in the defined order
522
+ ->withConfiguredRule (
523
+ OrderedClassElementsFixer::class,
524
+ [
525
+ 'order ' => [
526
+ 'use_trait ' ,
527
+ 'case ' , // enum values should be before other elements
528
+ 'constant ' ,
529
+ 'property ' ,
530
+ 'construct ' ,
531
+ 'destruct ' ,
532
+ 'magic ' ,
533
+ 'phpunit ' , // phpunit special methods like setUp should be before test methods
534
+ 'method ' ,
535
+ ],
536
+ ],
537
+ )
520
538
->withSkip ([
521
539
// We allow empty catch statements (but they must have comment - see EmptyCatchCommentSniff)
522
540
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 @@ -27,6 +27,8 @@ class Basic
27
27
return false ; // BlankLineBeforeStatementFixer
28
28
}
29
29
30
+ public const MY_PUBLIC_CONST = 333 ; // OrderedClassElementsFixer
31
+
30
32
public function fooBar (mixed $ foo ): mixed
31
33
{
32
34
// PhpdocToCommentFixer
@@ -45,4 +47,8 @@ class Basic
45
47
// TernaryToElvisOperatorFixer
46
48
return ($ foo ? $ foo : 'not true ' );
47
49
}
50
+
51
+ protected int $ myProperty = 666 ; // OrderedClassElementsFixer
52
+
53
+ use SomeUsefulTrait; // OrderedClassElementsFixer
48
54
}
You can’t perform that action at this time.
0 commit comments