| Conditions | 12 |
| Paths | 11 |
| Total Lines | 24 |
| Code Lines | 17 |
| 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 |
||
| 82 | public function check($value): void |
||
| 83 | { |
||
| 84 | if ($this->isArrayType($this->type)) { |
||
|
|
|||
| 85 | if (!is_array($value)) { |
||
| 86 | throw new InvalidArgumentException(); |
||
| 87 | } |
||
| 88 | } elseif ($this->isStringType($this->type)) { |
||
| 89 | if (!is_string($value)) { |
||
| 90 | throw new InvalidArgumentException(); |
||
| 91 | } |
||
| 92 | } elseif ($this->isIntegerType($this->type)) { |
||
| 93 | if (!is_int($value)) { |
||
| 94 | throw new InvalidArgumentException(); |
||
| 95 | } |
||
| 96 | } elseif ($this->isBoolType($this->type)) { |
||
| 97 | if (!is_bool($value)) { |
||
| 98 | throw new InvalidArgumentException(); |
||
| 99 | } |
||
| 100 | } elseif ($this->isClassOrInterfaceName($this->type)) { |
||
| 101 | if (!is_object($value) || !is_a($value, $this->type)) { |
||
| 102 | throw new InvalidArgumentException(); |
||
| 103 | } |
||
| 104 | } else { |
||
| 105 | throw new InvalidArgumentException(); |
||
| 106 | } |
||
| 109 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.