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 5555use PhpCsFixer \Fixer \CastNotation \ShortScalarCastFixer ;
5656use PhpCsFixer \Fixer \ClassNotation \ClassAttributesSeparationFixer ;
5757use PhpCsFixer \Fixer \ClassNotation \NoBlankLinesAfterClassOpeningFixer ;
58+ use PhpCsFixer \Fixer \ClassNotation \OrderedClassElementsFixer ;
5859use PhpCsFixer \Fixer \ClassNotation \SelfAccessorFixer ;
5960use PhpCsFixer \Fixer \ClassNotation \SingleTraitInsertPerStatementFixer ;
6061use PhpCsFixer \Fixer \ClassNotation \VisibilityRequiredFixer ;
519520 'use_trait ' ,
520521 ],
521522 ])
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+ )
522540 ->withSkip ([
523541 // We allow empty catch statements (but they must have comment - see EmptyCatchCommentSniff)
524542 EmptyStatementSniff::class . '.DetectedCatch ' => null ,
Original file line number Diff line number Diff line change @@ -4,8 +4,13 @@ use Bar\Foo; // NoUnneededImportAliasFixer
44
55class Basic
66{
7+ use SomeUsefulTrait; // OrderedClassElementsFixer
78 public const FOO = 'foo ' ; // ClassAttributesSeparationFixer
89
10+ public const MY_PUBLIC_CONST = 333 ; // OrderedClassElementsFixer
11+
12+ protected int $ myProperty = 666 ; // OrderedClassElementsFixer
13+
914 public function isEqual ($ a , ?string $ b ): ?bool // VisibilityRequiredFixer, CompactNullableTypeDeclarationFixer
1015 {
1116 // TrimArraySpacesFixer
Original file line number Diff line number Diff line change @@ -29,6 +29,8 @@ class Basic
2929 return false ; // BlankLineBeforeStatementFixer
3030 }
3131
32+ public const MY_PUBLIC_CONST = 333 ; // OrderedClassElementsFixer
33+
3234 public function fooBar (mixed $ foo ): mixed
3335 {
3436 // PhpdocToCommentFixer
@@ -47,4 +49,8 @@ class Basic
4749 // TernaryToElvisOperatorFixer
4850 return ($ foo ? $ foo : 'not true ' );
4951 }
52+
53+ protected int $ myProperty = 666 ; // OrderedClassElementsFixer
54+
55+ use SomeUsefulTrait; // OrderedClassElementsFixer
5056}
You can’t perform that action at this time.
0 commit comments