| Conditions | 10 |
| Paths | 33 |
| Total Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 22 |
| CRAP Score | 10.0082 |
| 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 |
||
| 15 | 21 | public function visit(\DOMElement $node, Compiler $context) |
|
| 16 | { |
||
| 17 | 21 | $code = "include "; |
|
| 18 | |||
| 19 | 21 | if ($node->hasAttribute("from-exp")) { |
|
| 20 | 3 | $code .= $node->getAttribute("from-exp"); |
|
| 21 | 21 | } elseif ($node->hasAttribute("from")) { |
|
| 22 | 18 | $code .= '"' . $node->getAttribute("from") . '"'; |
|
| 23 | 18 | } else { |
|
| 24 | throw new Exception("The 'from' or 'from-exp' attribute is required"); |
||
| 25 | } |
||
| 26 | |||
| 27 | 21 | if ($node->hasAttribute("ignore-missing") && $node->getAttribute("ignore-missing") !== "false") { |
|
| 28 | 3 | $code .= " ignore missing"; |
|
| 29 | 3 | } |
|
| 30 | 21 | if ($node->hasAttribute("with")) { |
|
| 31 | 9 | $code .= " with " . $node->getAttribute("with"); |
|
| 32 | 9 | } |
|
| 33 | 21 | if ($node->hasAttribute("only") && $node->getAttribute("only") !== "false") { |
|
| 34 | 3 | $code .= " only"; |
|
| 35 | 3 | } |
|
| 36 | 21 | if ($node->hasAttribute("sandboxed") && $node->getAttribute("sandboxed") !== "false") { |
|
| 37 | 3 | $code .= " sandboxed = true"; |
|
| 38 | 3 | } |
|
| 39 | |||
| 40 | 21 | $pi = $context->createControlNode($code); |
|
| 41 | 21 | $node->parentNode->replaceChild($pi, $node); |
|
| 42 | 21 | } |
|
| 43 | } |
||
| 44 |