Conditions | 19 |
Paths | 19 |
Total Lines | 39 |
Code Lines | 38 |
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 |
||
114 | public static function getColor($code, $default = 'white') { |
||
115 | switch(strtolower($code)) { |
||
116 | case '': |
||
117 | case 'white': |
||
118 | return 0xffffff; |
||
119 | case 'black': |
||
120 | return 0x000000; |
||
121 | case 'maroon': |
||
122 | return 0x800000; |
||
123 | case 'red': |
||
124 | return 0xff0000; |
||
125 | case 'orange': |
||
126 | return 0xffa500; |
||
127 | case 'yellow': |
||
128 | return 0xffff00; |
||
129 | case 'olive': |
||
130 | return 0x808000; |
||
131 | case 'purple': |
||
132 | return 0x800080; |
||
133 | case 'fuchsia': |
||
134 | return 0xff00ff; |
||
135 | case 'lime': |
||
136 | return 0x00ff00; |
||
137 | case 'green': |
||
138 | return 0x008000; |
||
139 | case 'navy': |
||
140 | return 0x000080; |
||
141 | case 'blue': |
||
142 | return 0x0000ff; |
||
143 | case 'aqua': |
||
144 | return 0x00ffff; |
||
145 | case 'teal': |
||
146 | return 0x008080; |
||
147 | case 'silver': |
||
148 | return 0xc0c0c0; |
||
149 | case 'gray': |
||
150 | return 0x808080; |
||
151 | default: |
||
152 | return self::getColor($default, 'white'); |
||
153 | } |
||
156 | ?> |
||
|
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.