| Total Complexity | 41 |
| Total Lines | 180 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like UserInfo often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UserInfo, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class UserInfo |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Get user agente. |
||
| 23 | * |
||
| 24 | * @since 1.0.0 |
||
| 25 | * |
||
| 26 | * @return agent |
||
|
|
|||
| 27 | */ |
||
| 28 | public static function agent() |
||
| 29 | { |
||
| 30 | return $_SERVER['HTTP_USER_AGENT']; |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Get OperatingSystem name. |
||
| 35 | * |
||
| 36 | * @since 1.0.0 |
||
| 37 | * |
||
| 38 | * @return void |
||
| 39 | */ |
||
| 40 | public function operatingSystem() |
||
| 41 | { |
||
| 42 | $UserAgent = self::agent(); |
||
| 43 | if (preg_match_all('/windows/i', $UserAgent)) { |
||
| 44 | $PlatForm = 'Windows'; |
||
| 45 | } elseif (preg_match_all('/linux/i', $UserAgent)) { |
||
| 46 | $PlatForm = 'Linux'; |
||
| 47 | } elseif (preg_match('/macintosh|mac os x/i', $UserAgent)) { |
||
| 48 | $PlatForm = 'Macintosh'; |
||
| 49 | } elseif (preg_match_all('/Android/i', $UserAgent)) { |
||
| 50 | $PlatForm = 'Android'; |
||
| 51 | } elseif (preg_match_all('/iPhone/i', $UserAgent)) { |
||
| 52 | $PlatForm = 'IOS'; |
||
| 53 | } elseif (preg_match_all('/ubuntu/i', $UserAgent)) { |
||
| 54 | $PlatForm = 'Ubuntu'; |
||
| 55 | } else { |
||
| 56 | $PlatForm = 'unknown'; |
||
| 57 | } |
||
| 58 | |||
| 59 | return $PlatForm; |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Get Browser Name. |
||
| 64 | * |
||
| 65 | * @since 1.0.0 |
||
| 66 | * |
||
| 67 | * @return void |
||
| 68 | */ |
||
| 69 | public function browser() |
||
| 70 | { |
||
| 71 | $UserAgent = self::agent(); |
||
| 72 | if (preg_match_all('/Edge/i', $UserAgent)) { |
||
| 73 | $Browser = 'Microsoft Edge'; |
||
| 74 | $B_Agent = 'Edge'; |
||
| 75 | } elseif (preg_match_all('/MSIE/i', $UserAgent)) { |
||
| 76 | $Browser = 'Mozilla Firefox'; |
||
| 77 | $B_Agent = 'Firefox'; |
||
| 78 | } elseif (preg_match_all('/OPR/i', $UserAgent)) { |
||
| 79 | $Browser = 'Opera'; |
||
| 80 | $B_Agent = 'Opera'; |
||
| 81 | } elseif (preg_match_all('/Opera/i', $UserAgent)) { |
||
| 82 | $Browser = 'Opera'; |
||
| 83 | $B_Agent = 'Opera'; |
||
| 84 | } elseif (preg_match_all('/Chrome/i', $UserAgent)) { |
||
| 85 | $Browser = 'Google Chrome'; |
||
| 86 | $B_Agent = 'Chrome'; |
||
| 87 | } elseif (preg_match_all('/Safari/i', $UserAgent)) { |
||
| 88 | $Browser = 'Apple Safari'; |
||
| 89 | $B_Agent = 'Safari'; |
||
| 90 | } elseif (preg_match_all('/firefox/i', $UserAgent)) { |
||
| 91 | $Browser = 'Mozilla Firefox'; |
||
| 92 | $B_Agent = 'Firefox'; |
||
| 93 | } else { |
||
| 94 | $Browser = null; |
||
| 95 | $B_Agent = null; |
||
| 96 | } |
||
| 97 | |||
| 98 | return [ |
||
| 99 | 'browser' => $Browser, |
||
| 100 | 'agent' => $B_Agent, |
||
| 101 | ]; |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Get Os version. |
||
| 106 | * |
||
| 107 | * @since 1.0.0 |
||
| 108 | * |
||
| 109 | * @return void |
||
| 110 | */ |
||
| 111 | public function oSVersion() |
||
| 112 | { |
||
| 113 | $UserAgent = self::agent(); |
||
| 114 | if (preg_match_all('/windows nt 10/i', $UserAgent)) { |
||
| 115 | $OsVersion = 'Windows 10'; |
||
| 116 | } elseif (preg_match_all('/windows nt 6.3/i', $UserAgent)) { |
||
| 117 | $OsVersion = 'Windows 8.1'; |
||
| 118 | } elseif (preg_match_all('/windows nt 6.2/i', $UserAgent)) { |
||
| 119 | $OsVersion = 'Windows 8'; |
||
| 120 | } elseif (preg_match_all('/windows nt 6.1/i', $UserAgent)) { |
||
| 121 | $OsVersion = 'Windows 7'; |
||
| 122 | } elseif (preg_match_all('/windows nt 6.0/i', $UserAgent)) { |
||
| 123 | $OsVersion = 'Windows Vista'; |
||
| 124 | } elseif (preg_match_all('/windows nt 5.1/i', $UserAgent)) { |
||
| 125 | $OsVersion = 'Windows Xp'; |
||
| 126 | } elseif (preg_match_all('/windows xp/i', $UserAgent)) { |
||
| 127 | $OsVersion = 'Windows Xp'; |
||
| 128 | } elseif (preg_match_all('/windows me/i', $UserAgent)) { |
||
| 129 | $OsVersion = 'Windows Me'; |
||
| 130 | } elseif (preg_match_all('/win98/i', $UserAgent)) { |
||
| 131 | $OsVersion = 'Windows 98'; |
||
| 132 | } elseif (preg_match_all('/win95/i', $UserAgent)) { |
||
| 133 | $OsVersion = 'Windows 95'; |
||
| 134 | } elseif (preg_match_all('/Windows Phone +[0-9]/i', $UserAgent, $match)) { |
||
| 135 | $OsVersion = $match; |
||
| 136 | } elseif (preg_match_all('/Android +[0-9]/i', $UserAgent, $match)) { |
||
| 137 | $OsVersion = $match; |
||
| 138 | } elseif (preg_match_all('/Linux +x[0-9]+/i', $UserAgent, $match)) { |
||
| 139 | $OsVersion = $match; |
||
| 140 | } elseif (preg_match_all('/mac os x [0-9]+/i', $UserAgent, $match)) { |
||
| 141 | $OsVersion = $match; |
||
| 142 | } elseif (preg_match_all('/os [0-9]+/i', $UserAgent, $match)) { |
||
| 143 | $OsVersion = $match; |
||
| 144 | } |
||
| 145 | |||
| 146 | return isset($OsVersion) ? $OsVersion : false; |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Get Browser version. |
||
| 151 | * |
||
| 152 | * @since 1.0.0 |
||
| 153 | * |
||
| 154 | * @return void |
||
| 155 | */ |
||
| 156 | public function browserVersion() |
||
| 179 | } |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Get The user ip. |
||
| 183 | * |
||
| 184 | * @since 1.0.0 |
||
| 185 | * |
||
| 186 | * @return void |
||
| 187 | */ |
||
| 188 | public function ip() |
||
| 199 | } |
||
| 200 | } |
||
| 201 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths