1 | <?php |
||
24 | class AlphabeticClassContentSniff extends AbstractSniff |
||
25 | { |
||
26 | use ClassRegistrationTrait; |
||
27 | |||
28 | /** |
||
29 | * You SHOULD sort you constants, methods and properties alphabetically. |
||
30 | */ |
||
31 | public const CODE_SORT_ALPHABETICALLY = 'SortAlphabetically'; |
||
32 | |||
33 | /** |
||
34 | * The message for the wrong sorting. |
||
35 | */ |
||
36 | private const MESSAGE_SORT_ALPHABETICALLY = 'Please sort you contents alphabetically.'; |
||
37 | |||
38 | /** |
||
39 | * Checks the sorting of both arrays and registered warnings, if a token is not on the correct position. |
||
40 | * |
||
41 | * @param array $foundContentsOrg The original contents with their position. |
||
42 | * @param array $foundContentsSorted The sorted contents without their position as array key. |
||
43 | * |
||
44 | * @return void |
||
45 | */ |
||
46 | private function checkAndRegisterSortingProblems(array $foundContentsOrg, array $foundContentsSorted): void |
||
60 | |||
61 | /** |
||
62 | * Loads every content for the token type and checks their sorting. |
||
63 | * |
||
64 | * @param int $token |
||
65 | * |
||
66 | * @return void |
||
67 | */ |
||
68 | private function checkAndRegisterSortingProblemsOfTypes(int $token): void |
||
76 | |||
77 | /** |
||
78 | * Returns the contents of the token type. |
||
79 | * |
||
80 | * @param int $token The contents with their position as array key. |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | private function getContentsOfTokenType(int $token): array |
||
112 | |||
113 | /** |
||
114 | * Processes the token. |
||
115 | * |
||
116 | * @return void |
||
117 | */ |
||
118 | protected function processToken(): void |
||
126 | |||
127 | /** |
||
128 | * Sorts the tokens and returns them without their position as array keys. |
||
129 | * |
||
130 | * @param array $foundContentsOrg |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | private function sortTokensWithoutPos(array $foundContentsOrg): array |
||
144 | } |
||
145 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: