| Conditions | 11 |
| Paths | 58 |
| Total Lines | 52 |
| Code Lines | 34 |
| 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 |
||
| 71 | public function render($diff) |
||
| 72 | { |
||
| 73 | $xi = $yi = 1; |
||
| 74 | $block = false; |
||
| 75 | $context = []; |
||
| 76 | |||
| 77 | $nlead = $this->_leading_context_lines; |
||
| 78 | $ntrail = $this->_trailing_context_lines; |
||
| 79 | |||
| 80 | $output = $this->_startDiff(); |
||
| 81 | |||
| 82 | foreach ($diff->getDiff() as $edit) { |
||
| 83 | if (is_a($edit, 'Text_Diff_Op_copy')) { |
||
| 84 | if (is_array($block)) { |
||
| 85 | if (count($edit->orig) <= $nlead + $ntrail) { |
||
| 86 | $block[] = $edit; |
||
| 87 | } else { |
||
| 88 | if ($ntrail) { |
||
| 89 | $context = array_slice($edit->orig, 0, $ntrail); |
||
| 90 | $block[] = new Text_Diff_Op_copy($context); |
||
| 91 | } |
||
| 92 | $output .= $this->_block($x0, $ntrail + $xi - $x0, $y0, $ntrail + $yi - $y0, $block); |
||
| 93 | $block = false; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | $context = $edit->orig; |
||
| 97 | } else { |
||
| 98 | if (!is_array($block)) { |
||
| 99 | $context = array_slice($context, count($context) - $nlead); |
||
| 100 | $x0 = $xi - count($context); |
||
| 101 | $y0 = $yi - count($context); |
||
| 102 | $block = []; |
||
| 103 | if ($context) { |
||
| 104 | $block[] = new Text_Diff_Op_copy($context); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | $block[] = $edit; |
||
| 108 | } |
||
| 109 | |||
| 110 | if ($edit->orig) { |
||
| 111 | $xi += count($edit->orig); |
||
| 112 | } |
||
| 113 | if ($edit->final) { |
||
| 114 | $yi += count($edit->final); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | if (is_array($block)) { |
||
| 119 | $output .= $this->_block($x0, $xi - $x0, $y0, $yi - $y0, $block); |
||
| 120 | } |
||
| 121 | |||
| 122 | return $output . $this->_endDiff(); |
||
| 123 | } |
||
| 256 |