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