| Conditions | 16 |
| Paths | 1081 |
| Total 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 |
||
| 37 | public static function getBrowserInfo(): object |
||
| 38 | { |
||
| 39 | if (empty(self::$browserCache)) { |
||
| 40 | $browserAgent = strtolower($_SERVER['HTTP_USER_AGENT']); |
||
| 41 | $browser = new \stdClass(); |
||
| 42 | $browser->win = false !== strpos($browserAgent, 'win'); |
||
| 43 | $browser->mac = false !== strpos($browserAgent, 'mac'); |
||
| 44 | $browser->linux = false !== strpos($browserAgent, 'linux'); |
||
| 45 | $browser->unix = false !== strpos($browserAgent, 'unix'); |
||
| 46 | $browser->webkit = false !== strpos($browserAgent, 'applewebkit'); |
||
| 47 | $browser->opera = false !== strpos($browserAgent, 'opera') || ($browser->webkit && false !== strpos($browserAgent, 'opr/')); |
||
| 48 | $browser->ns = false !== strpos($browserAgent, 'netscape'); |
||
| 49 | $browser->chrome = !$browser->opera && false !== strpos($browserAgent, 'chrome'); |
||
| 50 | $browser->ie = !$browser->opera && (false !== strpos($browserAgent, 'compatible; msie') || false !== strpos($browserAgent, 'trident/')); |
||
| 51 | $browser->safari = !$browser->opera && !$browser->chrome && ($browser->webkit || false !== strpos($browserAgent, 'safari')); |
||
| 52 | $browser->mz = !$browser->ie && !$browser->safari && !$browser->chrome && !$browser->ns && !$browser->opera && false !== strpos($browserAgent, 'mozilla'); |
||
| 53 | |||
| 54 | if (preg_match('/ ([a-z]{2})-([a-z]{2})/', $browserAgent, $regs)) { |
||
| 55 | $browser->lang = $regs[1]; |
||
| 56 | } else { |
||
| 57 | $browser->lang = 'en'; |
||
| 58 | } |
||
| 59 | $browser->https = self::isHttps(); |
||
| 60 | self::$browserCache = $browser; |
||
|
|
|||
| 61 | } |
||
| 62 | return self::$browserCache; |
||
| 63 | } |
||
| 64 | |||
| 92 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..