| Conditions | 13 |
| Paths | 26 |
| Total Lines | 52 |
| 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 |
||
| 142 | protected function callHelper( |
||
| 143 | $helper, |
||
| 144 | $key, |
||
| 145 | Translation $translation, |
||
| 146 | ArrayObject $results, |
||
| 147 | array $options, |
||
| 148 | $joinResult |
||
| 149 | ) { |
||
| 150 | $plugin = $this->helpers->get($helper); |
||
| 151 | foreach ($options as $func => $calls) { |
||
| 152 | if (null === $calls) { |
||
| 153 | continue; |
||
| 154 | } |
||
| 155 | |||
| 156 | foreach ($calls as $params) { |
||
| 157 | if (null === $params) { |
||
| 158 | continue; |
||
| 159 | } |
||
| 160 | |||
| 161 | $translation->merge($results->getArrayCopy())->getVarTranslation()->translate($params); |
||
| 162 | if (!is_array($params)) { |
||
| 163 | throw new Exception\LogicException('Expected params of type array'); |
||
| 164 | } |
||
| 165 | |||
| 166 | $plugin = call_user_func_array([$plugin, $func], $params); |
||
| 167 | if (is_string($plugin)) { |
||
| 168 | break; |
||
| 169 | } |
||
| 170 | |||
| 171 | if (!($plugin instanceof HelperInterface) |
||
| 172 | || is_array($plugin) |
||
| 173 | || is_int($plugin) |
||
| 174 | || is_float($plugin) |
||
| 175 | ) { |
||
| 176 | // support array results |
||
| 177 | $results[$key] = $plugin; |
||
| 178 | return $this; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 183 | empty($results[$key]) |
||
| 184 | and $results[$key] = null; |
||
| 185 | |||
| 186 | if ($joinResult) { |
||
| 187 | $results[$key].= $plugin; |
||
| 188 | } else { |
||
| 189 | $results[$key] = $plugin; |
||
| 190 | } |
||
| 191 | |||
| 192 | return $this; |
||
| 193 | } |
||
| 194 | } |
||
| 195 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.