Conditions | 11 |
Paths | 20 |
Total Lines | 28 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
15 | public function __construct(array $config) |
||
16 | { |
||
17 | parent::__construct($config); |
||
18 | |||
19 | $routes = method_exists(app(), 'getRoutes') ? app()->getRoutes() : app('router')->getRoutes(); |
||
20 | if ($routes instanceof \Illuminate\Routing\RouteCollection) { // Laravel |
||
21 | foreach ($routes->getRoutes() as $route) { |
||
22 | $method = $route->methods()[0]; |
||
23 | $uri = '/' . ltrim($route->uri(), '/'); |
||
24 | $this->routes[$method . $uri] = $uri; |
||
25 | |||
26 | $action = $route->getAction(); |
||
27 | if (is_string($action['uses'])) { // Uses |
||
28 | $this->routesByUses[$method . $action['uses']] = $uri; |
||
29 | } elseif ($action['uses'] instanceof Closure) { // Closure |
||
30 | $objectId = spl_object_hash($action['uses']); |
||
31 | $this->routesByClosure[$method . $objectId] = $uri; |
||
32 | } |
||
33 | } |
||
34 | } elseif (is_array($routes)) { // Lumen |
||
35 | $this->routes = $routes; |
||
36 | foreach ($routes as $route) { |
||
37 | if (isset($route['action']['uses'])) { // Uses |
||
38 | $this->routesByUses[$route['method'] . $route['action']['uses']] = $route['uri']; |
||
39 | } |
||
40 | if (isset($route['action'][0]) && $route['action'][0] instanceof Closure) { // Closure |
||
41 | $objectId = spl_object_hash($route['action'][0]); |
||
42 | $this->routesByClosure[$route['method'] . $objectId] = $route['uri']; |
||
43 | } |
||
119 | } |