| Conditions | 15 |
| Paths | 25 |
| Total Lines | 34 |
| Code Lines | 26 |
| 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 |
||
| 50 | private static function convertDomNodeToText(\DOMNode $node): string |
||
| 51 | { |
||
| 52 | if ($node instanceof \DOMText) { |
||
| 53 | $text = preg_replace('/\s+/', ' ', $node->wholeText); |
||
| 54 | } else { |
||
| 55 | $text = ''; |
||
| 56 | if ($node->childNodes !== null) { |
||
| 57 | foreach ($node->childNodes as $childNode) { |
||
| 58 | $text .= self::convertDomNodeToText($childNode); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | switch ($node->nodeName) { |
||
| 63 | case 'h1': |
||
| 64 | case 'h2': |
||
| 65 | case 'h3': |
||
| 66 | case 'h4': |
||
| 67 | case 'h5': |
||
| 68 | case 'h6': |
||
| 69 | case 'p': |
||
| 70 | case 'ul': |
||
| 71 | case 'div': |
||
| 72 | $text = "\n\n" . $text . "\n\n"; |
||
| 73 | break; |
||
| 74 | case 'li': |
||
| 75 | $text = '- ' . $text . "\n"; |
||
| 76 | break; |
||
| 77 | case 'br': |
||
| 78 | $text .= "\n"; |
||
| 79 | break; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | return $text; |
||
| 84 | } |
||
| 86 |