| Conditions | 11 |
| Paths | 9 |
| Total Lines | 25 |
| Code Lines | 18 |
| 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 |
||
| 69 | public static function getClientBrowser() |
||
| 70 | { |
||
| 71 | if(getenv('HTTP_USER_AGENT')) { |
||
| 72 | |||
| 73 | $userAgent = getenv('HTTP_USER_AGENT'); |
||
| 74 | |||
| 75 | if ((preg_match('/MSIE/i',$userAgent) || preg_match('/Trident/i',$userAgent)) && !preg_match('/Opera/i',$userAgent)) { |
||
|
|
|||
| 76 | return 'Internet Explorer'; |
||
| 77 | } elseif(preg_match('/Camino/i', $userAgent)) { |
||
| 78 | return "Camino"; |
||
| 79 | } elseif(preg_match('/Firefox/i', $userAgent)) { |
||
| 80 | return "Firefox"; |
||
| 81 | } elseif(preg_match('/Safari/i', $userAgent)) { |
||
| 82 | return "Safari"; |
||
| 83 | } elseif(preg_match('/Chrome/i', $userAgent)) { |
||
| 84 | return "Chrome"; |
||
| 85 | } elseif(preg_match('/Konqueror/i', $userAgent)) { |
||
| 86 | return "Konqueror"; |
||
| 87 | } elseif(preg_match('/Opera/i', $userAgent)) { |
||
| 88 | return "Opera"; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | return null; |
||
| 93 | } |
||
| 94 | } |
||
| 95 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.