| Conditions | 13 |
| Paths | 321 |
| Total Lines | 46 |
| Code Lines | 27 |
| 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 |
||
| 30 | public function renderTab(Representation $r) |
||
| 31 | { |
||
| 32 | if (!$r instanceof ColorRepresentation) { |
||
| 33 | return false; |
||
| 34 | } |
||
| 35 | |||
| 36 | $out = ''; |
||
| 37 | |||
| 38 | if ($color = $r->getColor(ColorRepresentation::COLOR_NAME)) { |
||
| 39 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
| 40 | } |
||
| 41 | if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_3)) { |
||
| 42 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
| 43 | } |
||
| 44 | if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_6)) { |
||
| 45 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
| 46 | } |
||
| 47 | |||
| 48 | if ($r->hasAlpha()) { |
||
| 49 | if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_4)) { |
||
| 50 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
| 51 | } |
||
| 52 | if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_8)) { |
||
| 53 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
| 54 | } |
||
| 55 | if ($color = $r->getColor(ColorRepresentation::COLOR_RGBA)) { |
||
| 56 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
| 57 | } |
||
| 58 | if ($color = $r->getColor(ColorRepresentation::COLOR_HSLA)) { |
||
| 59 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
| 60 | } |
||
| 61 | } else { |
||
| 62 | if ($color = $r->getColor(ColorRepresentation::COLOR_RGB)) { |
||
| 63 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
| 64 | } |
||
| 65 | if ($color = $r->getColor(ColorRepresentation::COLOR_HSL)) { |
||
| 66 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | if (!strlen($out)) { |
||
| 71 | return false; |
||
| 72 | } |
||
| 73 | |||
| 74 | return '<pre>'.$out.'</pre>'; |
||
| 75 | } |
||
| 76 | } |
||
| 77 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.