Conditions | 13 |
Paths | 321 |
Total Lines | 45 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
54 | public function renderTab(Representation $r) |
||
55 | { |
||
56 | if (!$r instanceof ColorRepresentation) { |
||
57 | return; |
||
58 | } |
||
59 | |||
60 | $out = ''; |
||
61 | |||
62 | if ($color = $r->getColor(ColorRepresentation::COLOR_NAME)) { |
||
63 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
64 | } |
||
65 | if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_3)) { |
||
66 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
67 | } |
||
68 | if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_6)) { |
||
69 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
70 | } |
||
71 | |||
72 | if ($r->hasAlpha()) { |
||
73 | if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_4)) { |
||
74 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
75 | } |
||
76 | if ($color = $r->getColor(ColorRepresentation::COLOR_HEX_8)) { |
||
77 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
78 | } |
||
79 | if ($color = $r->getColor(ColorRepresentation::COLOR_RGBA)) { |
||
80 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
81 | } |
||
82 | if ($color = $r->getColor(ColorRepresentation::COLOR_HSLA)) { |
||
83 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
84 | } |
||
85 | } else { |
||
86 | if ($color = $r->getColor(ColorRepresentation::COLOR_RGB)) { |
||
87 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
88 | } |
||
89 | if ($color = $r->getColor(ColorRepresentation::COLOR_HSL)) { |
||
90 | $out .= '<dfn>'.$color."</dfn>\n"; |
||
91 | } |
||
92 | } |
||
93 | |||
94 | if (!\strlen($out)) { |
||
95 | return false; |
||
96 | } |
||
97 | |||
98 | return '<pre>'.$out.'</pre>'; |
||
99 | } |
||
101 |