| Conditions | 5 |
| Paths | 5 |
| Total Lines | 53 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 91 | public function render() : string |
||
| 92 | { |
||
| 93 | $this->array = $this->diff->toArray(); |
||
| 94 | |||
| 95 | $i1 = $this->indentation; |
||
| 96 | $i2 = $this->indentation.$this->tab; |
||
| 97 | $i3 = $this->indentation.$this->tab.$this->tab; |
||
| 98 | $nl = PHP_EOL; |
||
| 99 | |||
| 100 | $html = ''; |
||
| 101 | |||
| 102 | // loop over the lines in the diff |
||
| 103 | $index = 0; |
||
| 104 | while ($index < count($this->array)) |
||
| 105 | { |
||
| 106 | $leftCell = ''; |
||
| 107 | $rightCell = ''; |
||
| 108 | |||
| 109 | // determine the line type |
||
| 110 | switch ($this->array[$index][1]) |
||
| 111 | { |
||
| 112 | // display the content on the left and right |
||
| 113 | case Diff::UNMODIFIED: |
||
| 114 | $leftCell = $this->getCellContent($index, Diff::UNMODIFIED); |
||
| 115 | $rightCell = $leftCell; |
||
| 116 | break; |
||
| 117 | |||
| 118 | // display the deleted on the left and inserted content on the right |
||
| 119 | case Diff::DELETED: |
||
| 120 | $leftCell = $this->getCellContent($index, Diff::DELETED); |
||
| 121 | $rightCell = $this->getCellContent($index, Diff::INSERTED); |
||
| 122 | break; |
||
| 123 | |||
| 124 | // display the inserted content on the right |
||
| 125 | case Diff::INSERTED: |
||
| 126 | $rightCell = $this->getCellContent($index, Diff::INSERTED); |
||
| 127 | break; |
||
| 128 | |||
| 129 | } |
||
| 130 | |||
| 131 | $leftType = $this->resolveLeftType($leftCell, $rightCell); |
||
| 132 | $rightType = $this->resolveRightType($leftCell, $rightCell); |
||
| 133 | |||
| 134 | // extend the HTML with the new row |
||
| 135 | $html .= |
||
| 136 | $i2. "<tr>". $nl . |
||
| 137 | $i3. '<td class="text-diff-'.$leftType. '">'. $leftCell . "</td>".$nl. |
||
| 138 | $i3. '<td class="text-diff-'.$rightType. '">'. $rightCell . "</td>".$nl. |
||
| 139 | $i2. "</tr>".$nl; |
||
| 140 | |||
| 141 | } |
||
| 142 | |||
| 143 | return $i1. sprintf($this->container, $nl.$html).$nl; |
||
| 144 | } |
||
| 216 |