| Conditions | 12 |
| Paths | 36 |
| Total Lines | 38 |
| Code Lines | 29 |
| 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 |
||
| 55 | public static function __callStatic(string $name, array $arguments): void |
||
| 56 | { |
||
| 57 | // Handle Exception-parameter |
||
| 58 | $exception = AssertionFailedException::class; |
||
| 59 | |||
| 60 | $last = end($arguments); |
||
| 61 | if (is_string($last) && class_exists($last) && is_subclass_of($last, Throwable::class)) { |
||
| 62 | $exception = $last; |
||
| 63 | array_pop($arguments); |
||
| 64 | } |
||
| 65 | |||
| 66 | try { |
||
| 67 | if (method_exists(static::class, $name)) { |
||
| 68 | call_user_func_array([static::class, $name], $arguments); |
||
| 69 | return; |
||
| 70 | } elseif (preg_match('/^nullOr(.*)$/i', $name, $matches)) { |
||
| 71 | $method = lcfirst($matches[1]); |
||
| 72 | if (method_exists(static::class, $method)) { |
||
| 73 | call_user_func_array([static::class, 'nullOr'], [[static::class, $method], $arguments]); |
||
| 74 | } elseif (method_exists(BaseAssert::class, $method)) { |
||
| 75 | call_user_func_array([static::class, 'nullOr'], [[BaseAssert::class, $method], $arguments]); |
||
| 76 | } else { |
||
| 77 | throw new BadMethodCallException(sprintf("Assertion named `%s` does not exists.", $method)); |
||
| 78 | } |
||
| 79 | } elseif (preg_match('/^all(.*)$/i', $name, $matches)) { |
||
| 80 | $method = lcfirst($matches[1]); |
||
| 81 | if (method_exists(static::class, $method)) { |
||
| 82 | call_user_func_array([static::class, 'all'], [[static::class, $method], $arguments]); |
||
| 83 | } elseif (method_exists(BaseAssert::class, $method)) { |
||
| 84 | call_user_func_array([static::class, 'all'], [[BaseAssert::class, $method], $arguments]); |
||
| 85 | } else { |
||
| 86 | throw new BadMethodCallException(sprintf("Assertion named `%s` does not exists.", $method)); |
||
| 87 | } |
||
| 88 | } else { |
||
| 89 | throw new BadMethodCallException(sprintf("Assertion named `%s` does not exists.", $name)); |
||
| 90 | } |
||
| 91 | } catch (InvalidArgumentException $e) { |
||
| 92 | throw new $exception($e->getMessage()); |
||
| 93 | } |
||
| 179 |