Conditions | 11 |
Paths | 25 |
Total Lines | 26 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
86 | * |
||
87 | * @throws ExitException |
||
88 | */ |
||
89 | protected function check_and_normalize_route_internal (&$path, $structure, $cli_or_api_path) { |
||
90 | /** |
||
91 | * If path not specified - take first from structure |
||
92 | */ |
||
93 | if (!$path) { |
||
94 | $path = isset($structure[0]) ? $structure[0] : array_keys($structure)[0]; |
||
95 | /** |
||
96 | * We need exact paths for CLI and API request (or `_` ending if available) and less strict mode for other cases that allows go deeper automatically |
||
97 | */ |
||
98 | if ($path !== '_' && $cli_or_api_path) { |
||
99 | throw new ExitException(404); |
||
100 | } |
||
101 | } elseif (!isset($structure[$path]) && !in_array($path, $structure)) { |
||
102 | throw new ExitException(404); |
||
103 | } |
||
104 | /** @noinspection PhpUndefinedMethodInspection */ |
||
105 | if (!$this->check_permission($path)) { |
||
106 | throw new ExitException(403); |
||
107 | } |
||
108 | } |
||
109 | /** |
||
110 | * If HTTP method handler not found we generate either `501 Not Implemented` if other methods are supported or `404 Not Found` if handlers for others |
||
111 | * methods also doesn't exist |
||
112 | * |
||
137 |