| Conditions | 10 |
| Paths | 6 |
| Total Lines | 35 |
| Code Lines | 20 |
| 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 |
||
| 90 | public function __call($name, $arguments) : self |
||
| 91 | { |
||
| 92 | if (strpos($name, 'set') > -1) { |
||
| 93 | $param = strtolower(str_replace('set', '', $name)); |
||
| 94 | $reflectionParam = null; |
||
| 95 | foreach ($this->reflactionArgsClass as $arg) { |
||
| 96 | if ($arg->getName() === $param) { |
||
| 97 | if ($arg->hasType()) { |
||
| 98 | if (gettype(current($arguments)) === 'object') { |
||
| 99 | $class = $arg->getType()->getName(); |
||
| 100 | if (current($arguments) instanceof $class) { |
||
| 101 | $reflectionParam = current($arguments); |
||
| 102 | continue; |
||
| 103 | } |
||
| 104 | } |
||
| 105 | $argType = $this->normalizeTypeReflection($arg->getType()->getName()); |
||
| 106 | if (gettype(current($arguments)) !== $argType) { |
||
| 107 | throw new \InvalidArgumentException(\sprintf('The parameter %s of %s class must be of the type %s', $param, $this->class, $argType)); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | $reflectionParam = current($arguments); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | if (is_null($reflectionParam)) { |
||
| 116 | throw new \BadMethodCallException(\sprintf('The parameter %s of %s class doesn\'t exist', $param, $this->class)); |
||
| 117 | } |
||
| 118 | |||
| 119 | if (!is_null($reflectionParam)) { |
||
| 120 | $this->parameters[$param] = $reflectionParam; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | return $this; |
||
| 125 | } |
||
| 197 |