| Conditions | 10 |
| Paths | 20 |
| Total Lines | 35 |
| 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 |
||
| 25 | public function __invoke(ArrayObject $loopArgument, array $options) |
||
| 26 | { |
||
| 27 | if (empty($options['elementName'])) { |
||
| 28 | throw new InvalidLoopHelperOptionException('elementName', $loopArgument['spec']); |
||
| 29 | } |
||
| 30 | if (!empty($options['elementAttribs']) && !is_array($options['elementAttribs'])) { |
||
| 31 | throw new InvalidLoopHelperOptionException('elementAttribs', $loopArgument['spec']); |
||
| 32 | } |
||
| 33 | if (empty($options['each'])) { |
||
| 34 | throw new InvalidLoopHelperOptionException('each', $loopArgument['spec']); |
||
| 35 | } |
||
| 36 | if (($loopArgument['index'] - 1) % $options['each']) { |
||
| 37 | return; |
||
| 38 | } |
||
| 39 | |||
| 40 | // create wrapper |
||
| 41 | $newParentNode = $loopArgument['parentNode']->ownerDocument |
||
| 42 | ->createElement($options['elementName']); |
||
| 43 | |||
| 44 | $parentNode = !empty($loopArgument['wrapperParentNode']) |
||
| 45 | ? $loopArgument['wrapperParentNode'] |
||
| 46 | : $loopArgument['wrapperParentNode'] = $loopArgument['parentNode']; |
||
| 47 | |||
| 48 | $beforeNode = !empty($loopArgument['wrapperBeforeNode']) |
||
| 49 | ? $loopArgument['wrapperBeforeNode'] |
||
| 50 | : $loopArgument['wrapperBeforeNode'] = $loopArgument['beforeNode']; |
||
| 51 | |||
| 52 | $loopArgument['beforeNode'] = null; |
||
| 53 | $loopArgument['parentNode'] = $beforeNode |
||
| 54 | ? $parentNode->insertBefore($newParentNode, $beforeNode) |
||
| 55 | : $parentNode->appendChild($newParentNode); |
||
| 56 | |||
| 57 | empty($options['elementAttribs']) or |
||
| 58 | $newParentNode->setAttributes($options['elementAttribs']); |
||
| 59 | } |
||
| 60 | } |
||
| 61 |