Conditions | 10 |
Paths | 15 |
Total Lines | 42 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
Bugs | 0 | Features | 0 |
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 |
||
133 | protected function doMatch($pathinfo, Request $request = null) |
||
134 | { |
||
135 | $matchedRoute = $this->router->match($pathinfo, $request->server->all()); |
||
136 | if ($matchedRoute === false) { |
||
137 | throw new ResourceNotFoundException(); |
||
138 | } |
||
139 | |||
140 | $routeParams = $matchedRoute->params; |
||
141 | |||
142 | // The 'action' key always exists and defaults to the Route Name, so we check accordingly |
||
143 | if (!isset($routeParams['controller']) && $routeParams['action'] === $matchedRoute->name) { |
||
144 | throw new \Exception('Matched the route: ' . $matchedRoute->name . ' but unable to locate |
||
145 | any controller/action params to dispatch'); |
||
146 | } |
||
147 | |||
148 | // We need _controller, to that symfony ControllerResolver can pick this up |
||
149 | if (!isset($routeParams['_controller'])) { |
||
150 | if (isset($routeParams['controller'])) { |
||
151 | $routeParams['_controller'] = $routeParams['controller']; |
||
152 | } elseif (isset($routeParams['action'])) { |
||
153 | $routeParams['_controller'] = $routeParams['action']; |
||
154 | } else { |
||
155 | throw new \Exception('Unable to determine the controller from route: ' . $matchedRoute->name); |
||
156 | } |
||
157 | } |
||
158 | |||
159 | $routeParams['_route'] = $matchedRoute->name; |
||
160 | |||
161 | // If the controller is an Object, and 'action' is defaulted to the route name - we default to __invoke |
||
162 | if ($routeParams['action'] === $matchedRoute->name) { |
||
163 | $routeParams['action'] = '__invoke'; |
||
164 | } |
||
165 | |||
166 | if (false === strpos($routeParams['_controller'], '::') && isset($routeParams['action'])) { |
||
167 | $routeParams['_controller'] = sprintf('%s::%s', |
||
168 | $routeParams['_controller'], |
||
169 | $routeParams['action'] |
||
170 | ); |
||
171 | } |
||
172 | |||
173 | return $routeParams; |
||
174 | } |
||
175 | } |
||
176 |