1 | <?php |
||
24 | class AlphabeticClassContentSniff extends AbstractSniff |
||
25 | { |
||
26 | use ClassRegistrationTrait; |
||
27 | |||
28 | /** |
||
29 | * Error code for the sorting. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | public const CODE_SORT_ALPHABETICALLY = 'SortAlphabetically'; |
||
34 | |||
35 | /** |
||
36 | * The message for the wrong sorting. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | private const MESSAGE_SORT_ALPHABETICALLY = 'Please sort you contents alphabetically.'; |
||
41 | |||
42 | /** |
||
43 | * Checks the sorting of both arrays and registered warnings, if a token is not on the correct position. |
||
44 | * |
||
45 | * @param array $foundContentsOrg The original contents with their position. |
||
46 | * @param array $foundContentsSorted The sorted contents without their position as array key. |
||
47 | * |
||
48 | * @return void |
||
49 | */ |
||
50 | private function checkAndRegisterSortingProblems(array $foundContentsOrg, array $foundContentsSorted): void |
||
64 | |||
65 | /** |
||
66 | * Loads every content for the token type and checks their sorting. |
||
67 | * |
||
68 | * @param int $token |
||
69 | * |
||
70 | * @return void |
||
71 | */ |
||
72 | private function checkAndRegisterSortingProblemsOfTypes(int $token): void |
||
80 | |||
81 | /** |
||
82 | * Returns the contents of the token type. |
||
83 | * |
||
84 | * @param int $token The contents with their position as array key. |
||
85 | * |
||
86 | * @return array |
||
87 | */ |
||
88 | private function getContentsOfTokenType(int $token): array |
||
116 | |||
117 | /** |
||
118 | * Processes the token. |
||
119 | * |
||
120 | * @return void |
||
121 | */ |
||
122 | protected function processToken(): void |
||
130 | |||
131 | /** |
||
132 | * Sorts the tokens and returns them without their position as array keys. |
||
133 | * |
||
134 | * @param array $foundContentsOrg |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | private function sortTokensWithoutPos(array $foundContentsOrg): array |
||
148 | } |
||
149 |
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: