| Conditions | 10 |
| Paths | 20 |
| Total Lines | 45 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 38 | protected function constructHtml($map = null, $recall = false) |
||
| 39 | { |
||
| 40 | static $markedUp; |
||
| 41 | |||
| 42 | $html = ''; |
||
| 43 | |||
| 44 | if (!$recall) { |
||
| 45 | $markedUp = []; |
||
| 46 | } |
||
| 47 | |||
| 48 | foreach ($map ?? $this->map as $currentElement => $definition) { |
||
| 49 | |||
| 50 | if (in_array($currentElement, $markedUp)) { |
||
| 51 | continue; |
||
| 52 | } |
||
| 53 | |||
| 54 | // add values already existing as strings to $html as they may already exist as markup |
||
| 55 | if (is_object($definition) && method_exists($definition, '__toString') || is_string($definition)) { |
||
|
|
|||
| 56 | $html .= $definition; |
||
| 57 | $markedUp[] = $currentElement; |
||
| 58 | continue; |
||
| 59 | } |
||
| 60 | |||
| 61 | $html .= Html::open($definition['tag'], $definition['attributes'] ?? ''); |
||
| 62 | $html .= $definition['content'] ?? ''; |
||
| 63 | |||
| 64 | // store children in array to be passed as $html_map argument in recursive call |
||
| 65 | if (!empty($children = $definition['children'] ?? null)) { |
||
| 66 | foreach ($children as $child) { |
||
| 67 | $childMap[$child] = $this->map[$child]; |
||
| 68 | } |
||
| 69 | |||
| 70 | $html .= $this->constructHtml($childMap, true); |
||
| 71 | } |
||
| 72 | |||
| 73 | $html .= Html::maybeClose($definition['tag']); |
||
| 74 | $markedUp[] = $currentElement; |
||
| 75 | } |
||
| 76 | |||
| 77 | // reset static variables if in initial call stack |
||
| 78 | if (!$recall) { |
||
| 79 | $markedUp = null; |
||
| 80 | } |
||
| 81 | |||
| 82 | return $html; |
||
| 83 | } |
||
| 117 |