| Conditions | 12 |
| Paths | 10 |
| Total Lines | 49 |
| Code Lines | 27 |
| 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 |
||
| 100 | private function transmogrify($obj, $val) |
||
| 101 | { |
||
| 102 | // Callbacks (lambda or callable) are supported. They must accept the source object as argument. |
||
| 103 | if (!is_string($val) && is_callable($val)) { |
||
| 104 | return $val($obj); |
||
| 105 | } |
||
| 106 | |||
| 107 | // Arrays or traversables are handled recursively. |
||
| 108 | // This also converts / casts any Traversable into a simple array. |
||
| 109 | if (is_array($val) || $val instanceof Traversable) { |
||
| 110 | $data = []; |
||
| 111 | foreach ($val as $k => $v) { |
||
| 112 | if (!is_string($k)) { |
||
| 113 | if (is_string($v)) { |
||
| 114 | $data[$v] = $this->objectGet($obj, $v); |
||
| 115 | } else { |
||
| 116 | $data[] = $v; |
||
| 117 | } |
||
| 118 | } else { |
||
| 119 | $data[$k] = $this->transmogrify($obj, $v); |
||
| 120 | } |
||
| 121 | } |
||
| 122 | return $data; |
||
| 123 | } |
||
| 124 | |||
| 125 | // Strings are handled by rendering {{property}} with dynamic object getter pattern. |
||
| 126 | if (is_string($val)) { |
||
| 127 | return preg_replace_callback($this->getterPattern, function(array $matches) use ($obj) { |
||
| 128 | return $this->objectGet($obj, $matches[1]); |
||
| 129 | }, $val); |
||
| 130 | } |
||
| 131 | |||
| 132 | if (is_numeric($val)) { |
||
| 133 | return $val; |
||
| 134 | } |
||
| 135 | |||
| 136 | if (is_bool($val)) { |
||
| 137 | return !!$val; |
||
| 138 | } |
||
| 139 | |||
| 140 | if ($val === null) { |
||
| 141 | return null; |
||
| 142 | } |
||
| 143 | |||
| 144 | // Any other |
||
| 145 | throw new InvalidArgumentException( |
||
| 146 | sprintf( |
||
| 147 | 'Presenter\'s transmogrify val needs to be callable, traversable (array) or a string. "%s" given.', |
||
| 148 | gettype($val) |
||
| 149 | ) |
||
| 186 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths