| Conditions | 10 |
| Paths | 5 |
| Total Lines | 27 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 118 | public static function fromArray(array $route) |
||
| 119 | { |
||
| 120 | if (!isset($route['pattern'])) { |
||
| 121 | throw new InvalidArgumentException('Required parameter pattern is not set.'); |
||
| 122 | } |
||
| 123 | |||
| 124 | if (!isset($route['method'])) { |
||
| 125 | throw new InvalidArgumentException('Required parameter method is not set.'); |
||
| 126 | } |
||
| 127 | |||
| 128 | if (!isset($route['controller'])) { |
||
| 129 | throw new InvalidArgumentException('Required parameter controller is not set.'); |
||
| 130 | } |
||
| 131 | |||
| 132 | if (isset($route['value']) && !is_array($route['value'])) { |
||
| 133 | $route['value'] = []; |
||
| 134 | } |
||
| 135 | |||
| 136 | return new self( |
||
| 137 | !is_array($route['method']) ? [$route['method']] : $route['method'], |
||
| 138 | $route['pattern'], |
||
| 139 | $route['controller'], |
||
| 140 | isset($route['assert']) ? $route['assert'] : [], |
||
| 141 | isset($route['value']) ? $route['value'] : [], |
||
| 142 | isset($route['name']) ? $route['name'] : '' |
||
|
|
|||
| 143 | ); |
||
| 144 | } |
||
| 145 | } |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.