1 | <?php |
||
23 | class MultipleReturnSniff extends AbstractSniff |
||
24 | { |
||
25 | use FunctionRegistrationTrait; |
||
26 | |||
27 | /** |
||
28 | * Code for multiple returns. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | public const CODE_MULTIPLE_RETURNS_FOUND = 'MultipleReturnsFound'; |
||
33 | |||
34 | /** |
||
35 | * Error message for multiple returns. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | private const WARNING_MULTIPLE_RETURNS_FOUND = 'Multiple returns detected. Did you refactor your method? Please ' . |
||
40 | 'do not use an early return if your method/function still is cluttered.'; |
||
41 | |||
42 | /** |
||
43 | * Only work on full fledged functions. |
||
44 | * |
||
45 | * @return bool True if there is a scope closer for this token. |
||
46 | */ |
||
47 | protected function areRequirementsMet(): bool |
||
51 | |||
52 | /** |
||
53 | * Returns the returns of this function. |
||
54 | * |
||
55 | * We check the "token level" to exclude the returns of nested closures. |
||
56 | * |
||
57 | * @return int[] The positions of the returns from the same function-scope. |
||
58 | */ |
||
59 | private function loadReturnsOfThisFunction(): array |
||
74 | |||
75 | /** |
||
76 | * Iterates through the returns of this function and registers warnings if there is more then one relevant return. |
||
77 | * |
||
78 | * @return void |
||
79 | */ |
||
80 | protected function processToken(): void |
||
96 | } |
||
97 |