Passed
Push — master ( 2b727f...c504f5 )
by ma
01:48
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.
src/ArrayTool.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * Description: Tool.php.
9 9
  */
10 10
 
11
-class ArrayTool{
11
+class ArrayTool {
12 12
 
13 13
     /**
14 14
      * @param $arr
@@ -16,20 +16,20 @@  discard block
 block discarded – undo
16 16
      * @param $type
17 17
      * @return array
18 18
      */
19
-    static public function arraySort($arr,$keys,$type='asc'){
19
+    static public function arraySort($arr, $keys, $type = 'asc') {
20 20
         $keysValue = $newArray = array();
21
-        foreach ($arr as $k=>$v){
22
-            if(isset($v[$keys])){
21
+        foreach ($arr as $k=>$v) {
22
+            if (isset($v[$keys])) {
23 23
                 $keysValue[$k] = $v[$keys];
24 24
             }
25 25
         }
26
-        if($type == 'asc'){
26
+        if ($type == 'asc') {
27 27
             asort($keysValue);
28
-        }else{
28
+        } else {
29 29
             arsort($keysValue);
30 30
         }
31 31
         reset($keysValue);
32
-        foreach ($keysValue as $k=>$v){
32
+        foreach ($keysValue as $k=>$v) {
33 33
             $newArray[$k] = $arr[$k];
34 34
         }
35 35
         return array_values($newArray);
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
      * @param int $parent_id 父id值
46 46
      * @return array
47 47
      */
48
-    public static function getTreeStructure($list,$filed='id',$parent_filed='pid',$parent_id=0){
48
+    public static function getTreeStructure($list, $filed = 'id', $parent_filed = 'pid', $parent_id = 0) {
49 49
         $result = array();
50
-        if(!empty($list)){
51
-            foreach($list as $key=>$val){
52
-                if($val[$parent_filed] == $parent_id){
53
-                    $val['child'] = self::getTreeStructure($list,$filed,$parent_filed,$val[$filed]);
54
-                    if(empty($val['child'])){
50
+        if (!empty($list)) {
51
+            foreach ($list as $key=>$val) {
52
+                if ($val[$parent_filed] == $parent_id) {
53
+                    $val['child'] = self::getTreeStructure($list, $filed, $parent_filed, $val[$filed]);
54
+                    if (empty($val['child'])) {
55 55
                         unset($val['child']);
56 56
                     }
57 57
                     $result[] = $val;
@@ -68,12 +68,12 @@  discard block
 block discarded – undo
68 68
      * @param $obj
69 69
      * @return array
70 70
      */
71
-    public static function objectToArray($obj){
72
-        if(!is_object($obj) && !is_array($obj)) {
71
+    public static function objectToArray($obj) {
72
+        if (!is_object($obj) && !is_array($obj)) {
73 73
             return $obj;
74 74
         }
75 75
         $arr = array();
76
-        foreach($obj as $k => $v){
76
+        foreach ($obj as $k => $v) {
77 77
             $arr[$k] = self::objectToArray($v);
78 78
         }
79 79
         return $arr;
@@ -85,12 +85,12 @@  discard block
 block discarded – undo
85 85
      * @Author: TinyMeng <[email protected]>
86 86
      * @param $data
87 87
      */
88
-    public static function nullArrayToObject(&$data){
89
-        foreach ($data as $key=>&$val){
90
-            if(is_array($val)){
91
-                if(empty($val)){
92
-                    settype($val,'object');
93
-                }else{
88
+    public static function nullArrayToObject(&$data) {
89
+        foreach ($data as $key=>&$val) {
90
+            if (is_array($val)) {
91
+                if (empty($val)) {
92
+                    settype($val, 'object');
93
+                } else {
94 94
                     self::nullArrayToObject($val);
95 95
                 }
96 96
             }
Please login to merge, or discard this patch.
src/async/AsyncHook.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace tinymeng\tools\async;
3 3
 
4
-class AsyncHook{
4
+class AsyncHook {
5 5
 
6 6
     /**
7 7
      * @var array
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
      */
21 21
     public static function hook(callable $callback, $params) {
22 22
         self::$hook_list[] = array('callback' => $callback, 'params' => $params);
23
-        if(self::$hooked === false) {
23
+        if (self::$hooked === false) {
24 24
             self::$hooked = true;
25 25
             //注册一个callback当前在脚本执行完后执行
26 26
             register_shutdown_function(array(__CLASS__, '__run'));
@@ -33,10 +33,10 @@  discard block
 block discarded – undo
33 33
      */
34 34
     private static function __run() {
35 35
         fastcgi_finish_request();
36
-        if(empty(self::$hook_list)) {
36
+        if (empty(self::$hook_list)) {
37 37
             return;
38 38
         }
39
-        foreach(self::$hook_list as $hook) {
39
+        foreach (self::$hook_list as $hook) {
40 40
             $callback = $hook['callback'];
41 41
             $params = $hook['params'];
42 42
             call_user_func_array($callback, $params);
Please login to merge, or discard this patch.
src/core/Singleton.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@  discard block
 block discarded – undo
13 13
      */
14 14
     private static $instance = null;
15 15
 
16
-    public function __construct($config=[]){
16
+    public function __construct($config = []) {
17 17
         $this->config = $config;
18 18
     }
19 19
 
20
-    private function __clone(){}
20
+    private function __clone() {}
21 21
 
22 22
     public function __sleep(): array
23 23
     {
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
         return [];
26 26
     }
27 27
 
28
-    protected static function init($gateway, $config=[])
28
+    protected static function init($gateway, $config = [])
29 29
     {
30 30
         if (!self::$instance instanceof static) {
31 31
             self::$instance = new static($config);
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      *@author: JiaMeng <[email protected]>
42 42
      * Updater:
43 43
      */
44
-    public static function __callStatic($gateway, array $config=[])
44
+    public static function __callStatic($gateway, array $config = [])
45 45
     {
46 46
         return self::init($gateway, ...$config);
47 47
     }
Please login to merge, or discard this patch.
src/HttpRequest.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -33,19 +33,19 @@  discard block
 block discarded – undo
33 33
      * @return bool|string
34 34
      * @throws \Exception
35 35
      */
36
-    static public function httpPost(string $url, array $param = array(), array $httpHeaders = array(), string $proxy='', int $http_code = 200)
36
+    static public function httpPost(string $url, array $param = array(), array $httpHeaders = array(), string $proxy = '', int $http_code = 200)
37 37
     {
38 38
         /** 参数检测,object或者array进行http_build_query */
39
-        if(!empty($param) && is_array($param)){
39
+        if (!empty($param) && is_array($param)) {
40 40
             $flag = false;
41
-            foreach ($param as $value){
41
+            foreach ($param as $value) {
42 42
                 //判断参数是否是一个对象 或者 是一个数组
43
-                if(is_array($value) || (is_string($value) && is_object($value))){
43
+                if (is_array($value) || (is_string($value) && is_object($value))) {
44 44
                     $flag = true;
45 45
                     break;
46 46
                 }
47 47
             }
48
-            if($flag == true){
48
+            if ($flag == true) {
49 49
                 $param = http_build_query($param);
50 50
             }
51 51
         }
@@ -62,12 +62,12 @@  discard block
 block discarded – undo
62 62
         curl_setopt($curl, CURLOPT_POSTFIELDS, $param);
63 63
 
64 64
         /** 设置请求headers */
65
-        if(empty($httpHeaders)){
65
+        if (empty($httpHeaders)) {
66 66
             $httpHeaders = array(
67 67
                 "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36"
68 68
             );
69 69
         }
70
-        if (is_array($httpHeaders)){
70
+        if (is_array($httpHeaders)) {
71 71
             curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders);
72 72
         }
73 73
         /** gzip压缩 */
@@ -81,11 +81,11 @@  discard block
 block discarded – undo
81 81
         }
82 82
 
83 83
         /** http代理 */
84
-        if(!empty($proxy)){
85
-            $proxy = explode(':',$proxy);
84
+        if (!empty($proxy)) {
85
+            $proxy = explode(':', $proxy);
86 86
             curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式
87 87
             curl_setopt($curl, CURLOPT_PROXY, "$proxy[0]"); //代理服务器地址
88
-            curl_setopt($curl, CURLOPT_PROXYPORT,$proxy[1]); //代理服务器端口
88
+            curl_setopt($curl, CURLOPT_PROXYPORT, $proxy[1]); //代理服务器端口
89 89
         }
90 90
 
91 91
         /** 请求 */
@@ -95,20 +95,20 @@  discard block
 block discarded – undo
95 95
         /** 关闭请求资源 */
96 96
         curl_close($curl);
97 97
 
98
-        if($http_code !== null){
98
+        if ($http_code !== null) {
99 99
             /** 验证网络请求状态 */
100 100
             if (intval($info["http_code"]) === 0) {
101 101
                 throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD,
102
-                    '[httpPost]: POST request was aborted ! Request url :' . $url . ' , post request data : ' . var_export($param,true)
102
+                    '[httpPost]: POST request was aborted ! Request url :'.$url.' , post request data : '.var_export($param, true)
103 103
                 );
104
-            }elseif(intval($info["http_code"]) != $http_code){
104
+            }elseif (intval($info["http_code"]) != $http_code) {
105 105
                 throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD,
106
-                    '[httpPost]: POST request was aborted ! Request url :' . $url . ' , post request data : ' . var_export($param,true).' ,return code : '.$info["http_code"] .' ,return content : '.$content
106
+                    '[httpPost]: POST request was aborted ! Request url :'.$url.' , post request data : '.var_export($param, true).' ,return code : '.$info["http_code"].' ,return content : '.$content
107 107
                 );
108 108
             } else {
109 109
                 return $content;
110 110
             }
111
-        }else{
111
+        } else {
112 112
             return $content;
113 113
         }
114 114
     }
@@ -125,13 +125,13 @@  discard block
 block discarded – undo
125 125
      * @return bool|string
126 126
      * @throws \Exception
127 127
      */
128
-    static public function httpGet($url, $param = array(), $httpHeaders = array(),$proxy= '',  $http_code = 200)
128
+    static public function httpGet($url, $param = array(), $httpHeaders = array(), $proxy = '', $http_code = 200)
129 129
     {
130 130
         $curl = curl_init();
131 131
 
132 132
         /** 设置请求参数 */
133 133
         if (!empty($param)) {
134
-            $url = $url . '?' . http_build_query($param);
134
+            $url = $url.'?'.http_build_query($param);
135 135
         }
136 136
 
137 137
         /** 设置请求链接 */
@@ -147,20 +147,20 @@  discard block
 block discarded – undo
147 147
         }
148 148
 
149 149
         /** http代理 */
150
-        if(!empty($proxy)){
151
-            $proxy = explode(':',$proxy);
150
+        if (!empty($proxy)) {
151
+            $proxy = explode(':', $proxy);
152 152
             curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式
153 153
             curl_setopt($curl, CURLOPT_PROXY, "$proxy[0]"); //代理服务器地址
154
-            curl_setopt($curl, CURLOPT_PROXYPORT,$proxy[1]); //代理服务器端口
154
+            curl_setopt($curl, CURLOPT_PROXYPORT, $proxy[1]); //代理服务器端口
155 155
         }
156 156
 
157 157
         /** 设置请求headers */
158
-        if(empty($httpHeaders)){
158
+        if (empty($httpHeaders)) {
159 159
             $httpHeaders = array(
160 160
                 "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36"
161 161
             );
162 162
         }
163
-        if (is_array($httpHeaders)){
163
+        if (is_array($httpHeaders)) {
164 164
             curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders);
165 165
         }
166 166
         /** gzip压缩 */
@@ -174,19 +174,19 @@  discard block
 block discarded – undo
174 174
         curl_close($curl);
175 175
 
176 176
         /** 验证网络请求状态 */
177
-        if($http_code !== null){
177
+        if ($http_code !== null) {
178 178
             if (intval($info["http_code"]) === 0) {
179 179
                 throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD,
180
-                    '[httpGet]: GET request was aborted ! Request url :' . $url
180
+                    '[httpGet]: GET request was aborted ! Request url :'.$url
181 181
                 );
182
-            }elseif(intval($info["http_code"]) != $http_code){
182
+            }elseif (intval($info["http_code"]) != $http_code) {
183 183
                 throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD,
184
-                    '[httpGet]: GET request was aborted ! Request url :' . $url .' ,return code : '.$info["http_code"] .' ,return content : '.$content
184
+                    '[httpGet]: GET request was aborted ! Request url :'.$url.' ,return code : '.$info["http_code"].' ,return content : '.$content
185 185
                 );
186 186
             } else {
187 187
                 return $content;
188 188
             }
189
-        }else{
189
+        } else {
190 190
             return $content;
191 191
         }
192 192
     }
Please login to merge, or discard this patch.
src/exception/TException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
         $this->setHeaders($headers);
22 22
 
23 23
         /** message */
24
-        if(empty($message)) $message = StatusCode::$status_code[$statusCode] ?? StatusCode::$status_code[StatusCode::COMMON_UNKNOWN];
24
+        if (empty($message)) $message = StatusCode::$status_code[$statusCode] ?? StatusCode::$status_code[StatusCode::COMMON_UNKNOWN];
25 25
         parent::__construct('ERROR tinymeng tools: '.$message, $code, $previous);
26 26
     }
27 27
 
Please login to merge, or discard this patch.