Passed
Push — master ( 93b7a9...f85b1c )
by ma
01:47
created
src/UrlTool.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 /**
4 4
  * Url
5 5
  */
6
-class UrlTool{
6
+class UrlTool {
7 7
 
8 8
     /**
9 9
      * 获取url中主域名
@@ -11,16 +11,16 @@  discard block
 block discarded – undo
11 11
      * @return string
12 12
      */
13 13
     static public function getMainDomain($url) {
14
-        $url = strtolower($url);//首先转成小写
14
+        $url = strtolower($url); //首先转成小写
15 15
         $host = parse_url($url, PHP_URL_HOST); // 获取host部分
16
-        if(empty($host)){
16
+        if (empty($host)) {
17 17
             $url = "https://".$url;
18
-            $host = parse_url($url,PHP_URL_HOST);
18
+            $host = parse_url($url, PHP_URL_HOST);
19 19
         }
20 20
         if (!$host) {
21 21
             return '';
22 22
         }
23
-        if (in_array($host,['127.0.0.1','localhost'])) {
23
+        if (in_array($host, ['127.0.0.1', 'localhost'])) {
24 24
             return '';
25 25
         }
26 26
 
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
          *  判断是否是双后缀aaa.com.cn
35 35
          */
36 36
         $preg = '/[\w].+\.(com|net|org|gov|edu)\.cn$/';
37
-        if ($count > 2 && preg_match($preg,$host)){
37
+        if ($count > 2 && preg_match($preg, $host)) {
38 38
             //双后缀取后3位
39
-            $host = $parts[$count-3].'.'.$parts[$count-2].'.'.$parts[$count-1];
40
-        } else{
39
+            $host = $parts[$count - 3].'.'.$parts[$count - 2].'.'.$parts[$count - 1];
40
+        } else {
41 41
             // 如果只有两个部分,则直接返回整个host作为主域名
42
-            $host = $parts[$count-2].'.'.$parts[$count-1];
42
+            $host = $parts[$count - 2].'.'.$parts[$count - 1];
43 43
         }
44 44
         return $host;
45 45
     }
Please login to merge, or discard this patch.