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