| Conditions | 11 |
| Paths | 58 |
| Total Lines | 57 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 67 | function render($diff) |
||
| 68 | { |
||
| 69 | $xi = $yi = 1; |
||
| 70 | $block = false; |
||
| 71 | $context = array(); |
||
| 72 | |||
| 73 | $nlead = $this->_leading_context_lines; |
||
| 74 | $ntrail = $this->_trailing_context_lines; |
||
| 75 | |||
| 76 | $output = $this->_startDiff(); |
||
| 77 | |||
| 78 | foreach ($diff->getDiff() as $edit) { |
||
| 79 | if (is_a($edit, 'Text_Diff_Op_copy')) { |
||
| 80 | if (is_array($block)) { |
||
| 81 | if (count($edit->orig) <= $nlead + $ntrail) { |
||
| 82 | $block[] = $edit; |
||
| 83 | } else { |
||
| 84 | if ($ntrail) { |
||
| 85 | $context = array_slice($edit->orig, 0, $ntrail); |
||
| 86 | $block[] = new Text_Diff_Op_copy($context); |
||
| 87 | } |
||
| 88 | $output .= $this->_block($x0, $ntrail + $xi - $x0, |
||
| 89 | $y0, $ntrail + $yi - $y0, |
||
| 90 | $block); |
||
| 91 | $block = false; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | $context = $edit->orig; |
||
| 95 | } else { |
||
| 96 | if (!is_array($block)) { |
||
| 97 | $context = array_slice($context, count($context) - $nlead); |
||
| 98 | $x0 = $xi - count($context); |
||
| 99 | $y0 = $yi - count($context); |
||
| 100 | $block = array(); |
||
| 101 | if ($context) { |
||
| 102 | $block[] = new Text_Diff_Op_copy($context); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | $block[] = $edit; |
||
| 106 | } |
||
| 107 | |||
| 108 | if ($edit->orig) { |
||
| 109 | $xi += count($edit->orig); |
||
| 110 | } |
||
| 111 | if ($edit->final) { |
||
| 112 | $yi += count($edit->final); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | if (is_array($block)) { |
||
| 117 | $output .= $this->_block($x0, $xi - $x0, |
||
| 118 | $y0, $yi - $y0, |
||
| 119 | $block); |
||
| 120 | } |
||
| 121 | |||
| 122 | return $output . $this->_endDiff(); |
||
| 123 | } |
||
| 124 | |||
| 210 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.