| Conditions | 12 |
| Paths | 11 |
| Total Lines | 24 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 71 | public function checkType($value, string $type): void |
||
| 72 | { |
||
| 73 | if ($this->isArrayType($type)) { |
||
| 74 | if (!is_array($value)) { |
||
| 75 | throw new InvalidArgumentException(); |
||
| 76 | } |
||
| 77 | } elseif ($this->isStringType($type)) { |
||
| 78 | if (!is_string($value)) { |
||
| 79 | throw new InvalidArgumentException(); |
||
| 80 | } |
||
| 81 | } elseif ($this->isIntegerType($type)) { |
||
| 82 | if (!is_int($value)) { |
||
| 83 | throw new InvalidArgumentException(); |
||
| 84 | } |
||
| 85 | } elseif ($this->isBoolType($type)) { |
||
| 86 | if (!is_bool($value)) { |
||
| 87 | throw new InvalidArgumentException(); |
||
| 88 | } |
||
| 89 | } elseif ($this->isClassOrInterfaceName($type)) { |
||
| 90 | if (!is_object($value) || !is_a($value, $type)) { |
||
| 91 | throw new InvalidArgumentException(); |
||
| 92 | } |
||
| 93 | } else { |
||
| 94 | throw new InvalidArgumentException(); |
||
| 95 | } |
||
| 98 |