Passed
Push — master ( 23e15f...93b7a9 )
by ma
02:33 queued 14s
created
src/FileTool.php 2 patches
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@  discard block
 block discarded – undo
4 4
  * 文件操作类
5 5
  *  logFilePath: /storage/tinymeng/log/
6 6
  */
7
-define('logFilePath',dirname(dirname(dirname(dirname(__DIR__)))).DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.'tinymeng'.DIRECTORY_SEPARATOR.'log'.DIRECTORY_SEPARATOR);
8
-class FileTool{
7
+define('logFilePath', dirname(dirname(dirname(dirname(__DIR__)))).DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.'tinymeng'.DIRECTORY_SEPARATOR.'log'.DIRECTORY_SEPARATOR);
8
+class FileTool {
9 9
 
10 10
     /**
11 11
      * Name: writeLog
@@ -16,26 +16,26 @@  discard block
 block discarded – undo
16 16
      * @param \Exception|null $exception
17 17
      * @return bool
18 18
      */
19
-    static public function writeLog($message, $file_name='error',bool $echo = false,\Exception $exception = null){
20
-        if(!is_string($message)){
19
+    static public function writeLog($message, $file_name = 'error', bool $echo = false, \Exception $exception = null) {
20
+        if (!is_string($message)) {
21 21
             $message = json_encode($message);
22 22
         }
23 23
         $message = date('Y-m-d H:i:s').' : '.$message.PHP_EOL;
24
-        if($exception && $exception instanceof \Exception){
24
+        if ($exception && $exception instanceof \Exception) {
25 25
             $message .= ' File: '.$exception->getFile().' ,Line: '.$exception->getLine().' ,Message: '.$exception->getMessage();
26 26
         }
27
-        if($echo){
27
+        if ($echo) {
28 28
             echo $message;
29 29
         }
30 30
         $path = logFilePath;
31 31
         if (!is_dir($path)) {
32
-            if(!mkdir($path, 0755, true)){
32
+            if (!mkdir($path, 0755, true)) {
33 33
                 die('创建缓存文件夹"'.$path.'"失败!');
34 34
             }
35 35
         }
36 36
 
37 37
         $file_name = $path.$file_name;
38
-        self::filePutContents($file_name."-".date('Ymd',time()).".log",$message,true);
38
+        self::filePutContents($file_name."-".date('Ymd', time()).".log", $message, true);
39 39
         return true;
40 40
     }
41 41
 
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
      * file_put_contents和fopen,fwrite,fclose三个组合的区别
49 49
      * http://blog.majiameng.com/article/2724.html
50 50
      */
51
-    static public function filePutContents(string $file_name,string $content,bool $file_append = false){
52
-        if(strrpos($file_name,DIRECTORY_SEPARATOR)){
51
+    static public function filePutContents(string $file_name, string $content, bool $file_append = false) {
52
+        if (strrpos($file_name, DIRECTORY_SEPARATOR)) {
53 53
             //获取文件夹路径
54
-            $dir_name = substr($file_name,0,strrpos($file_name,DIRECTORY_SEPARATOR));
54
+            $dir_name = substr($file_name, 0, strrpos($file_name, DIRECTORY_SEPARATOR));
55 55
             //创建文件夹
56 56
             self::mkdir($dir_name);
57 57
         }
@@ -60,10 +60,10 @@  discard block
 block discarded – undo
60 60
         self::chmod($file_name);
61 61
 
62 62
         //内容写入文件
63
-        if($file_append === false){
64
-            file_put_contents($file_name,$content);
65
-        }else{
66
-            file_put_contents($file_name,$content,FILE_APPEND);
63
+        if ($file_append === false) {
64
+            file_put_contents($file_name, $content);
65
+        } else {
66
+            file_put_contents($file_name, $content, FILE_APPEND);
67 67
         }
68 68
     }
69 69
 
@@ -76,10 +76,10 @@  discard block
 block discarded – undo
76 76
      * file_put_contents和fopen,fwrite,fclose三个组合的区别
77 77
      * http://blog.majiameng.com/article/2724.html
78 78
      */
79
-    static public function fWrite(string $file_name,string $content,bool $file_append = false){
80
-        if(strrpos($file_name,DIRECTORY_SEPARATOR)){
79
+    static public function fWrite(string $file_name, string $content, bool $file_append = false) {
80
+        if (strrpos($file_name, DIRECTORY_SEPARATOR)) {
81 81
             //获取文件夹路径
82
-            $dir_name = substr($file_name,0,strrpos($file_name,DIRECTORY_SEPARATOR));
82
+            $dir_name = substr($file_name, 0, strrpos($file_name, DIRECTORY_SEPARATOR));
83 83
             //创建文件夹
84 84
             self::mkdir($dir_name);
85 85
         }
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
         self::chmod($file_name);
89 89
 
90 90
         //内容写入文件
91
-        if($file_append === false){
91
+        if ($file_append === false) {
92 92
             $handle = fopen($file_name, 'w');
93 93
             fwrite($handle, $content);
94 94
             fclose($handle);
95
-        }else{
95
+        } else {
96 96
             $handle = fopen($file_name, 'a');
97 97
             fwrite($handle, $content);
98 98
             fclose($handle);
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
      * @param $dir_name
106 106
      * @return bool
107 107
      */
108
-    static public function mkdir(string $dir_name){
108
+    static public function mkdir(string $dir_name) {
109 109
         if (!is_dir($dir_name)) {
110
-            if(!mkdir($dir_name, 0755, true)){
110
+            if (!mkdir($dir_name, 0755, true)) {
111 111
                 die('创建缓存文件夹"'.$dir_name.'"失败!');
112 112
             }
113 113
             //添加文件权限
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
      * @return bool
124 124
      */
125 125
     static public function delDir(string $dir) {
126
-        if(!file_exists($dir)){//文件不存在
126
+        if (!file_exists($dir)) {//文件不存在
127 127
             return true;
128 128
         }
129 129
         if (!is_dir($dir)) {
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
         //先删除目录下的文件
135 135
         $dh = opendir($dir);
136 136
         while ($file = readdir($dh)) {
137
-            if($file != "." && $file!="..") {
137
+            if ($file != "." && $file != "..") {
138 138
                 $full_path = $dir."/".$file;
139
-                if(!is_dir($full_path)) {
139
+                if (!is_dir($full_path)) {
140 140
                     unlink($full_path);
141 141
                 } else {
142 142
                     self::delDir($full_path);
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
         closedir($dh);
147 147
 
148 148
         //删除当前文件夹:
149
-        if(rmdir($dir)) {
149
+        if (rmdir($dir)) {
150 150
             return true;
151 151
         } else {
152 152
             return false;
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
      * @param $file_name
160 160
      * @param int $mode
161 161
      */
162
-    static public function chmod($file_name,$mode = 0755){
163
-        if (file_exists($file_name)){
164
-            @chmod($file_name,$mode);
162
+    static public function chmod($file_name, $mode = 0755) {
163
+        if (file_exists($file_name)) {
164
+            @chmod($file_name, $mode);
165 165
         }
166 166
     }
167 167
 
@@ -172,12 +172,12 @@  discard block
 block discarded – undo
172 172
      * dirname()可以的当前文件目录
173 173
      * @return array
174 174
      */
175
-    static public function scanDir($path){
175
+    static public function scanDir($path) {
176 176
         $filename = scandir($path);
177 177
         $result = array();
178
-        foreach($filename as $k=>$v){
178
+        foreach ($filename as $k=>$v) {
179 179
             // 跳过两个特殊目录   continue跳出循环
180
-            if($v=="." || $v==".."){continue;}
180
+            if ($v == "." || $v == "..") {continue; }
181 181
             $result[] = $v;
182 182
         }
183 183
         return $result;
@@ -193,21 +193,21 @@  discard block
 block discarded – undo
193 193
     static public function move(string $file, string $new_file): bool
194 194
     {
195 195
         //文件是否存在
196
-        if(!file_exists($file)){
196
+        if (!file_exists($file)) {
197 197
             return false;
198 198
         }
199 199
 
200 200
         //新文件目录
201
-        if(strrpos($new_file,DIRECTORY_SEPARATOR)){
201
+        if (strrpos($new_file, DIRECTORY_SEPARATOR)) {
202 202
             //获取文件夹路径
203
-            $dir_name = substr($new_file,0,strrpos($new_file,DIRECTORY_SEPARATOR));
203
+            $dir_name = substr($new_file, 0, strrpos($new_file, DIRECTORY_SEPARATOR));
204 204
             //创建文件夹
205 205
             self::mkdir($dir_name);
206 206
             //添加文件权限
207 207
             self::chmod($dir_name);
208 208
         }
209 209
 
210
-        copy($file,$new_file); //拷贝到新目录
210
+        copy($file, $new_file); //拷贝到新目录
211 211
         unlink($file); //删除旧目录下的文件
212 212
 
213 213
         return true;
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         //内容写入文件
63 63
         if($file_append === false){
64 64
             file_put_contents($file_name,$content);
65
-        }else{
65
+        } else{
66 66
             file_put_contents($file_name,$content,FILE_APPEND);
67 67
         }
68 68
     }
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
             $handle = fopen($file_name, 'w');
93 93
             fwrite($handle, $content);
94 94
             fclose($handle);
95
-        }else{
95
+        } else{
96 96
             $handle = fopen($file_name, 'a');
97 97
             fwrite($handle, $content);
98 98
             fclose($handle);
Please login to merge, or discard this patch.
src/StringTool.php 2 patches
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -40,16 +40,16 @@  discard block
 block discarded – undo
40 40
     static public function createChannelId($namespace = ''):string {
41 41
         static $guid = '';
42 42
         $uid = uniqid("", true);
43
-        $data = $namespace. md5(time() . mt_rand(1,1000000)).uniqid();
44
-        $hash = strtoupper(hash('ripemd128', $uid . $guid . md5($data)));
45
-        $guid = substr($hash, 0, 8) .
46
-            '-' .
47
-            substr($hash, 8, 4) .
48
-            '-' .
49
-            substr($hash, 12, 4) .
50
-            '-' .
51
-            substr($hash, 16, 4) .
52
-            '-' .
43
+        $data = $namespace.md5(time().mt_rand(1, 1000000)).uniqid();
44
+        $hash = strtoupper(hash('ripemd128', $uid.$guid.md5($data)));
45
+        $guid = substr($hash, 0, 8).
46
+            '-'.
47
+            substr($hash, 8, 4).
48
+            '-'.
49
+            substr($hash, 12, 4).
50
+            '-'.
51
+            substr($hash, 16, 4).
52
+            '-'.
53 53
             substr($hash, 20, 12);
54 54
         return $guid;
55 55
     }
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
      * @return string
63 63
      */
64 64
     static public function md5Bit16($str):string {
65
-        return strtoupper(substr(md5($str),8,16));
65
+        return strtoupper(substr(md5($str), 8, 16));
66 66
     }
67 67
 
68 68
     /**
@@ -72,15 +72,15 @@  discard block
 block discarded – undo
72 72
      * @return int
73 73
      */
74 74
     static public function millisecond($time = null) :int{
75
-        if(empty($time)){
75
+        if (empty($time)) {
76 76
             list($msec, $sec) = explode(' ', microtime());
77
-            $millisecond = (int)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
78
-        }elseif(is_numeric($time) && strlen((string)$time)==10){
79
-            $millisecond = (string)$time."000";
80
-        }else{
77
+            $millisecond = (int) sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
78
+        }elseif (is_numeric($time) && strlen((string) $time) == 10) {
79
+            $millisecond = (string) $time."000";
80
+        } else {
81 81
             $millisecond = strtotime($time)."000";
82 82
         }
83
-        return (int)$millisecond;
83
+        return (int) $millisecond;
84 84
     }
85 85
 
86 86
     /**
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      * @param string $string
90 90
      * @return bool
91 91
      */
92
-    public static function isContainChinese($string=''):bool {
92
+    public static function isContainChinese($string = ''):bool {
93 93
         $result = preg_match('/[\x{4e00}-\x{9fa5}]/u', $string);
94 94
         return $result == 0 ? false : true;
95 95
     }
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      * @param string $string
101 101
      * @return bool
102 102
      */
103
-    public static function isAllChinese($string=''):bool {
103
+    public static function isAllChinese($string = ''):bool {
104 104
         $result = preg_match('/^[\x{4e00}-\x{9fa5}]+$/u', $string);
105 105
         return $result == 0 ? false : true;
106 106
     }
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
      * @param string $string
113 113
      * @return bool
114 114
      */
115
-    public static function isMobile($string=''):bool {
115
+    public static function isMobile($string = ''):bool {
116 116
         if (!preg_match("/(^1[3|4|5|7|8][0-9]{9}$)/", $string)) {
117 117
             return false;
118 118
         }
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
      * @param int $double   小数点保留位数 默认3位
128 128
      * @return string
129 129
      */
130
-    public static function sctonum($num, $double = 3){
131
-        if(false !== stripos($num, "e")){
132
-            $a = explode("e",strtolower($num));
130
+    public static function sctonum($num, $double = 3) {
131
+        if (false !== stripos($num, "e")) {
132
+            $a = explode("e", strtolower($num));
133 133
             return bcmul($a[0], bcpow(10, $a[1], $double), $double);
134 134
         }
135 135
         return $num;
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
      * @param string $to
144 144
      * @return array|false|string|string[]|null
145 145
      */
146
-    public static function autoCharset($string, $from='gbk', $to='utf-8') {
146
+    public static function autoCharset($string, $from = 'gbk', $to = 'utf-8') {
147 147
         $from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from;
148 148
         $to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to;
149 149
         if (strtoupper($from) === strtoupper($to) || empty($string) || (is_scalar($string) && !is_string($string))) {
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
      * @param $html
180 180
      * @return string
181 181
      */
182
-    public static function filterATag($html=''):string {
182
+    public static function filterATag($html = ''):string {
183 183
         return preg_replace("#<a[^>]*>(.*?)</a>#is", "$1", $html);
184 184
     }
185 185
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
      * @param $html
191 191
      * @return string
192 192
      */
193
-    public static function deleteATag($html=''):string {
193
+    public static function deleteATag($html = ''):string {
194 194
         return preg_replace("#<a[^>]*>(.*?)</a>#is", "", $html);
195 195
     }
196 196
 
@@ -202,36 +202,36 @@  discard block
 block discarded – undo
202 202
      * @param bool $is_timestamp   是否是时间戳
203 203
      * @return string
204 204
      */
205
-    public static function getTime($date,$is_timestamp=false):string {
206
-        if($is_timestamp === true){
205
+    public static function getTime($date, $is_timestamp = false):string {
206
+        if ($is_timestamp === true) {
207 207
             $time = $date;
208
-        }else{
209
-            $time = strtotime($date);//时间转换为时间戳
208
+        } else {
209
+            $time = strtotime($date); //时间转换为时间戳
210 210
         }
211 211
 
212
-        if($time >= time()){
212
+        if ($time >= time()) {
213 213
             return '刚刚';
214 214
         }
215 215
         $seconds = time() - $time;
216
-        if($seconds <= 60){
216
+        if ($seconds <= 60) {
217 217
             return '刚刚';
218 218
         }
219 219
         $minutes = intval($seconds / 60);
220
-        if($minutes <= 60){
220
+        if ($minutes <= 60) {
221 221
             return $minutes.'分钟前';
222 222
         }
223 223
         $hours = intval($minutes / 60);
224
-        if($hours <= 24){
224
+        if ($hours <= 24) {
225 225
             return $hours.'小时前';
226 226
         }
227 227
         $days = intval($hours / 24);
228
-        if($days <= 3){
228
+        if ($days <= 3) {
229 229
             return $days.'天前';
230 230
         }
231
-        if($days <= 365){
232
-            return date('m-d',/** @scrutinizer ignore-type */ $time);
231
+        if ($days <= 365) {
232
+            return date('m-d', /** @scrutinizer ignore-type */ $time);
233 233
         }
234
-        return date('Y-m-d',$time);
234
+        return date('Y-m-d', $time);
235 235
     }
236 236
 
237 237
     /**
@@ -245,11 +245,11 @@  discard block
 block discarded – undo
245 245
         $compress = '';
246 246
         foreach ($chunks as $c) {
247 247
             if (strtolower(substr($c, 0, 19)) == '<!--<nocompress>-->') {
248
-                $c        = substr($c, 19, strlen($c) - 19 - 20);
248
+                $c = substr($c, 19, strlen($c) - 19 - 20);
249 249
                 $compress .= $c;
250 250
                 continue;
251 251
             } elseif (strtolower(substr($c, 0, 12)) == '<nocompress>') {
252
-                $c        = substr($c, 12, strlen($c) - 12 - 13);
252
+                $c = substr($c, 12, strlen($c) - 12 - 13);
253 253
                 $compress .= $c;
254 254
                 continue;
255 255
             } elseif (strtolower(substr($c, 0, 4)) == '<pre' || strtolower(substr($c, 0, 9)) == '<textarea') {
@@ -297,14 +297,14 @@  discard block
 block discarded – undo
297 297
      * @return mixed
298 298
      */
299 299
     static public function htmlReplaceXcx(string $content):string {
300
-        $content = str_replace("\r\n","",$content);//出除回车和换行符
301
-        $content = preg_replace("/style=\".*?\"/si",'',$content);//style样式
302
-        $content = preg_replace(["/<strong.*?>/si", "/<\/strong>/si"],['<text class="wx-strong">','</text>'],$content);//strong
303
-        $content = preg_replace(["/<p.*?>/si", "/<\/p>/si"],['<view class="wx-p">','</view>'],$content);//p
304
-        $content = preg_replace(["/<a.*?>/si", "/<\/a>/si"],['<text class="wx-a">','</text>'],$content);//a
305
-        $content = preg_replace(["/<span.*?>/si", "/<\/span>/si"],['<text class="wx-span">','</text>'],$content);//span
306
-        $content = preg_replace(["/<h[1-6].*?>/si", "/<\/h[1-6]>/si"],['<view class="wx-h">','</view>'],$content);//h
307
-        $content = preg_replace("/<img.*?/si",'<image class="wx-img"',$content);//img
300
+        $content = str_replace("\r\n", "", $content); //出除回车和换行符
301
+        $content = preg_replace("/style=\".*?\"/si", '', $content); //style样式
302
+        $content = preg_replace(["/<strong.*?>/si", "/<\/strong>/si"], ['<text class="wx-strong">', '</text>'], $content); //strong
303
+        $content = preg_replace(["/<p.*?>/si", "/<\/p>/si"], ['<view class="wx-p">', '</view>'], $content); //p
304
+        $content = preg_replace(["/<a.*?>/si", "/<\/a>/si"], ['<text class="wx-a">', '</text>'], $content); //a
305
+        $content = preg_replace(["/<span.*?>/si", "/<\/span>/si"], ['<text class="wx-span">', '</text>'], $content); //span
306
+        $content = preg_replace(["/<h[1-6].*?>/si", "/<\/h[1-6]>/si"], ['<view class="wx-h">', '</view>'], $content); //h
307
+        $content = preg_replace("/<img.*?/si", '<image class="wx-img"', $content); //img
308 308
         return $content;
309 309
     }
310 310
 
@@ -316,8 +316,8 @@  discard block
 block discarded – undo
316 316
      * @return string
317 317
      */
318 318
     static public function pReplaceSpan(string $content):string {
319
-        $content = str_replace(["\r","\n","\t"],'',$content);
320
-        $content = preg_replace(["/<p/si", "/<\/p>/si"],['<span','</span><br>'],$content);//p
319
+        $content = str_replace(["\r", "\n", "\t"], '', $content);
320
+        $content = preg_replace(["/<p/si", "/<\/p>/si"], ['<span', '</span><br>'], $content); //p
321 321
         return $content;
322 322
     }
323 323
 
@@ -328,10 +328,10 @@  discard block
 block discarded – undo
328 328
      * @param  string $keyword
329 329
      * @return string
330 330
      */
331
-    static public function filterPunctuation($keyword){
332
-        $keyword = str_replace(["\r\n", "\r", "\n"," "," "], "", trim($keyword));//删除空格
333
-        $keyword = preg_replace('# #','',$keyword);
334
-        $keyword = preg_replace("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/",'',$keyword);
331
+    static public function filterPunctuation($keyword) {
332
+        $keyword = str_replace(["\r\n", "\r", "\n", " ", " "], "", trim($keyword)); //删除空格
333
+        $keyword = preg_replace('# #', '', $keyword);
334
+        $keyword = preg_replace("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/", '', $keyword);
335 335
         return $keyword;
336 336
     }
337 337
 
@@ -343,9 +343,9 @@  discard block
 block discarded – undo
343 343
      * @param string $allowable_tags
344 344
      * @return string
345 345
      */
346
-    static public function stripTags($content,$allowable_tags = '<font>'){
347
-        $content = strip_tags($content,$allowable_tags);//替换标签
348
-        $content = str_replace(["\r\n", "\r", "\n"," "], "", trim($content));//删除空格
346
+    static public function stripTags($content, $allowable_tags = '<font>') {
347
+        $content = strip_tags($content, $allowable_tags); //替换标签
348
+        $content = str_replace(["\r\n", "\r", "\n", " "], "", trim($content)); //删除空格
349 349
         return $content;
350 350
     }
351 351
 
Please login to merge, or discard this patch.
Braces   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
         if(empty($time)){
76 76
             list($msec, $sec) = explode(' ', microtime());
77 77
             $millisecond = (int)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
78
-        }elseif(is_numeric($time) && strlen((string)$time)==10){
78
+        } elseif(is_numeric($time) && strlen((string)$time)==10){
79 79
             $millisecond = (string)$time."000";
80
-        }else{
80
+        } else{
81 81
             $millisecond = strtotime($time)."000";
82 82
         }
83 83
         return (int)$millisecond;
@@ -162,12 +162,12 @@  discard block
 block discarded – undo
162 162
             foreach ($string as $key => $val) {
163 163
                 $_key = self::autoCharset($key, $from, $to);
164 164
                 $string[$_key] = self::autoCharset($val, $from, $to);
165
-                if ($key != $_key)
166
-                    unset($string[$key]);
165
+                if ($key != $_key) {
166
+                                    unset($string[$key]);
167
+                }
167 168
             }
168 169
             return $string;
169
-        }
170
-        else {
170
+        } else {
171 171
             return $string;
172 172
         }
173 173
     }
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
     public static function getTime($date,$is_timestamp=false):string {
206 206
         if($is_timestamp === true){
207 207
             $time = $date;
208
-        }else{
208
+        } else{
209 209
             $time = strtotime($date);//时间转换为时间戳
210 210
         }
211 211
 
Please login to merge, or discard this patch.
src/Tool.php 2 patches
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@
 block discarded – undo
19 19
     public static function getIp(){
20 20
         if(!empty($_SERVER["HTTP_CLIENT_IP"])){
21 21
             $cip = $_SERVER["HTTP_CLIENT_IP"];
22
-        }else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
22
+        } else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
23 23
             $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
24
-        }else if(!empty($_SERVER["REMOTE_ADDR"])){
24
+        } else if(!empty($_SERVER["REMOTE_ADDR"])){
25 25
             $cip = $_SERVER["REMOTE_ADDR"];
26
-        }else{
26
+        } else{
27 27
             $cip = '';
28 28
         }
29 29
         preg_match("/[\d\.]{7,15}/", $cip, $cips);
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 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 Tool{
11
+class Tool {
12 12
 
13 13
     /**
14 14
      * Description:  获取ip
@@ -16,14 +16,14 @@  discard block
 block discarded – undo
16 16
      * Updater:
17 17
      * @return string
18 18
      */
19
-    public static function getIp(){
20
-        if(!empty($_SERVER["HTTP_CLIENT_IP"])){
19
+    public static function getIp() {
20
+        if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
21 21
             $cip = $_SERVER["HTTP_CLIENT_IP"];
22
-        }else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
22
+        } else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
23 23
             $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
24
-        }else if(!empty($_SERVER["REMOTE_ADDR"])){
24
+        } else if (!empty($_SERVER["REMOTE_ADDR"])) {
25 25
             $cip = $_SERVER["REMOTE_ADDR"];
26
-        }else{
26
+        } else {
27 27
             $cip = '';
28 28
         }
29 29
         preg_match("/[\d\.]{7,15}/", $cip, $cips);
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      * Updater:
40 40
      * @return string
41 41
      */
42
-    public static function getOrigin(){
42
+    public static function getOrigin() {
43 43
         $origin = '';
44 44
         if (isset($_SERVER['HTTP_X_ORIGINAL_FOR'])) {
45 45
             $origin = $_SERVER['HTTP_X_ORIGINAL_FOR'];
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
                 'mobile'
105 105
             );
106 106
             // 从HTTP_USER_AGENT中查找手机浏览器的关键字
107
-            if (preg_match("/(" . implode('|', $clientKeyWords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
107
+            if (preg_match("/(".implode('|', $clientKeyWords).")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
108 108
                 return true;
109 109
             }
110 110
         }
Please login to merge, or discard this patch.
src/ZipTool.php 2 patches
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -19,10 +19,10 @@  discard block
 block discarded – undo
19 19
      */
20 20
     public $client;
21 21
 
22
-    static public function init(){
22
+    static public function init() {
23 23
         $gateway = new self();
24 24
 
25
-        $gateway->client =  new ZipArchive();
25
+        $gateway->client = new ZipArchive();
26 26
         return $gateway;
27 27
     }
28 28
 
@@ -33,29 +33,29 @@  discard block
 block discarded – undo
33 33
      * @author: Tinymeng <[email protected]>
34 34
      * @time: 2022/4/27 9:26
35 35
      */
36
-    public function open($filename,$Fromfilename=null){
37
-        if (!empty($filename)){
36
+    public function open($filename, $Fromfilename = null) {
37
+        if (!empty($filename)) {
38 38
             $this->setFileName($filename);
39
-            if(!$this->client->open($this->fileName, ZipArchive::CREATE))
39
+            if (!$this->client->open($this->fileName, ZipArchive::CREATE))
40 40
                 return 'File open failed';
41 41
         }
42
-        if(!empty($Fromfilename)){
43
-            if(is_dir($Fromfilename)){
42
+        if (!empty($Fromfilename)) {
43
+            if (is_dir($Fromfilename)) {
44 44
                 $list_dir = scandir($Fromfilename);
45
-                for($i=2;$i<count($list_dir);$i++){
46
-                    if(is_dir($Fromfilename.'/'.$list_dir[$i])){
45
+                for ($i = 2; $i < count($list_dir); $i++) {
46
+                    if (is_dir($Fromfilename.'/'.$list_dir[$i])) {
47 47
                         $this->client->addGlob($Fromfilename.'/'.$list_dir[$i].'/*.*', 0, array('add_path' => $Fromfilename.'/'.$list_dir[$i].'/', 'remove_path' => $Fromfilename.'/'.$list_dir[$i]));
48 48
                         $list_chr = scandir($Fromfilename.'/'.$list_dir[$i]);
49
-                        for($j=2;$j<count($list_chr);$j++){
50
-                            if(is_dir($Fromfilename.'/'.$list_dir[$i].'/'.$list_chr[$j])){
49
+                        for ($j = 2; $j < count($list_chr); $j++) {
50
+                            if (is_dir($Fromfilename.'/'.$list_dir[$i].'/'.$list_chr[$j])) {
51 51
                                 echo $list_chr[$j];
52
-                                $this->open('',$Fromfilename.'/'.$list_dir[$i].'/'.$list_chr[$j]);
52
+                                $this->open('', $Fromfilename.'/'.$list_dir[$i].'/'.$list_chr[$j]);
53 53
                             }
54 54
                         }
55 55
                     }
56 56
                 }
57
-            }else{
58
-                $this->client->addFile ($Fromfilename);
57
+            } else {
58
+                $this->client->addFile($Fromfilename);
59 59
             }
60 60
         }
61 61
         return $this;
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
      * @author: Tinymeng <[email protected]>
69 69
      * @time: 2022/4/27 9:26
70 70
      */
71
-    private function setFileName($filename){
72
-        if(!preg_match('/zip/m', $filename)){
73
-            $filename = $filename.'-'.date('Ymd').rand(111,999).'.zip';
71
+    private function setFileName($filename) {
72
+        if (!preg_match('/zip/m', $filename)) {
73
+            $filename = $filename.'-'.date('Ymd').rand(111, 999).'.zip';
74 74
         }
75 75
         $this->fileName = $filename;
76 76
         return $filename;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      * @author: Tinymeng <[email protected]>
83 83
      * @time: 2022/4/27 9:50
84 84
      */
85
-    public function getFileName(){
85
+    public function getFileName() {
86 86
         return $this->fileName;
87 87
     }
88 88
 
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
      * @author: Tinymeng <[email protected]>
95 95
      * @time: 2022/4/27 9:31
96 96
      */
97
-    public function addFileContent($file_name,$content){
98
-        $this->client->addFromString($file_name,$content);
97
+    public function addFileContent($file_name, $content) {
98
+        $this->client->addFromString($file_name, $content);
99 99
         return $this;
100 100
     }
101 101
 
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
      * @author: Tinymeng <[email protected]>
108 108
      * @time: 2022/4/27 9:31
109 109
      */
110
-    public function addFile($file_name,$content){
111
-        $this->client->addFromString($file_name,$content);
110
+    public function addFile($file_name, $content) {
111
+        $this->client->addFromString($file_name, $content);
112 112
         return $this;
113 113
     }
114 114
 
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      * 文件下载
117 117
      * @return void
118 118
      */
119
-    public function download(){
119
+    public function download() {
120 120
         $this->client->finish();
121 121
     }
122 122
 
@@ -128,17 +128,17 @@  discard block
 block discarded – undo
128 128
      * @author: Tinymeng <[email protected]>
129 129
      * @time: 2022/4/27 9:38
130 130
      */
131
-    public function unzip($filename,$dir){
132
-        if(!file_exists($filename))
131
+    public function unzip($filename, $dir) {
132
+        if (!file_exists($filename))
133 133
             return 'File does not exist';
134
-        if(!$this->client->open($filename))
134
+        if (!$this->client->open($filename))
135 135
             return 'File open failed';
136
-        if(!is_dir($dir)){
137
-            mkdir($dir,775);
138
-        }else{
136
+        if (!is_dir($dir)) {
137
+            mkdir($dir, 775);
138
+        } else {
139 139
             return 'Dir mk failed';
140 140
         }
141
-        if(!$this->client->extractTo($dir))
141
+        if (!$this->client->extractTo($dir))
142 142
             return 'File unzip failed';
143 143
         return $this;
144 144
     }
Please login to merge, or discard this patch.
Braces   +14 added lines, -10 removed lines patch added patch discarded remove patch
@@ -36,8 +36,9 @@  discard block
 block discarded – undo
36 36
     public function open($filename,$Fromfilename=null){
37 37
         if (!empty($filename)){
38 38
             $this->setFileName($filename);
39
-            if(!$this->client->open($this->fileName, ZipArchive::CREATE))
40
-                return 'File open failed';
39
+            if(!$this->client->open($this->fileName, ZipArchive::CREATE)) {
40
+                            return 'File open failed';
41
+            }
41 42
         }
42 43
         if(!empty($Fromfilename)){
43 44
             if(is_dir($Fromfilename)){
@@ -54,7 +55,7 @@  discard block
 block discarded – undo
54 55
                         }
55 56
                     }
56 57
                 }
57
-            }else{
58
+            } else{
58 59
                 $this->client->addFile ($Fromfilename);
59 60
             }
60 61
         }
@@ -129,17 +130,20 @@  discard block
 block discarded – undo
129 130
      * @time: 2022/4/27 9:38
130 131
      */
131 132
     public function unzip($filename,$dir){
132
-        if(!file_exists($filename))
133
-            return 'File does not exist';
134
-        if(!$this->client->open($filename))
135
-            return 'File open failed';
133
+        if(!file_exists($filename)) {
134
+                    return 'File does not exist';
135
+        }
136
+        if(!$this->client->open($filename)) {
137
+                    return 'File open failed';
138
+        }
136 139
         if(!is_dir($dir)){
137 140
             mkdir($dir,775);
138
-        }else{
141
+        } else{
139 142
             return 'Dir mk failed';
140 143
         }
141
-        if(!$this->client->extractTo($dir))
142
-            return 'File unzip failed';
144
+        if(!$this->client->extractTo($dir)) {
145
+                    return 'File unzip failed';
146
+        }
143 147
         return $this;
144 148
     }
145 149
 
Please login to merge, or discard this patch.
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
     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/UniqueId.php 2 patches
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
  *
35 35
  * php -r 'echo dechex( 0b00111111 );'
36 36
  */
37
-class UniqueId{
37
+class UniqueId {
38 38
 
39 39
 
40 40
     protected static $g_cInstanceDId;
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
     /**
51 51
      * __construct
52 52
      */
53
-    public function __construct(){}
53
+    public function __construct() {}
54 54
 
55 55
     /**
56 56
      * __destruct
57 57
      */
58
-    public function __destruct(){}
58
+    public function __destruct() {}
59 59
 
60 60
     /**
61 61
      * getInstance
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      */
64 64
     static function getInstance()
65 65
     {
66
-        if ( is_null( self::$g_cInstanceDId ) || ! isset( self::$g_cInstanceDId ) )
66
+        if (is_null(self::$g_cInstanceDId) || !isset(self::$g_cInstanceDId))
67 67
         {
68 68
             self::$g_cInstanceDId = new self();
69 69
         }
@@ -80,42 +80,42 @@  discard block
 block discarded – undo
80 80
      *	@param $arrData &array	details about the id
81 81
      *	@return int(64)	id
82 82
      */
83
-    public function createId( $nCenter, $nNode, $sSource = null, & $arrData = null )
83
+    public function createId($nCenter, $nNode, $sSource = null, & $arrData = null)
84 84
     {
85
-        if ( ! $this->isValidCenterId( $nCenter ) )
85
+        if (!$this->isValidCenterId($nCenter))
86 86
         {
87 87
             return null;
88 88
         }
89
-        if ( ! $this->isValidNodeId( $nNode ) )
89
+        if (!$this->isValidNodeId($nNode))
90 90
         {
91 91
             return null;
92 92
         }
93 93
 
94 94
         //	...
95
-        $nRet	= 0;
96
-        $nTime	= $this->getEscapedTime();
95
+        $nRet = 0;
96
+        $nTime = $this->getEscapedTime();
97 97
 
98
-        if ( is_string( $sSource ) && strlen( $sSource ) > 0 )
98
+        if (is_string($sSource) && strlen($sSource) > 0)
99 99
         {
100 100
             //	use crc32 hash value instead of rand
101
-            $nRand	= crc32( $sSource );
101
+            $nRand = crc32($sSource);
102 102
         }
103 103
         else
104 104
         {
105 105
             //	0 ~ 4095
106
-            $nRand	= rand( 0, 0xFFF );
106
+            $nRand = rand(0, 0xFFF);
107 107
         }
108 108
 
109 109
         //	...
110
-        $nCenterV	= ( ( $nCenter << 17 ) & 0x00000000003E0000 );
111
-        $nNodeV		= ( ( $nNode   << 12 ) & 0x000000000001F000 );
112
-        $nTimeV		= ( ( $nTime   << 22 ) & 0x7FFFFFFFFFC00000 );
113
-        $nRandV		= ( ( $nRand   << 0  ) & 0x0000000000000FFF );
110
+        $nCenterV = (($nCenter << 17) & 0x00000000003E0000);
111
+        $nNodeV		= (($nNode << 12) & 0x000000000001F000);
112
+        $nTimeV		= (($nTime << 22) & 0x7FFFFFFFFFC00000);
113
+        $nRandV		= (($nRand << 0) & 0x0000000000000FFF);
114 114
 
115
-        $nRet		= ( $nCenterV + $nNodeV + $nTimeV + $nRandV );
115
+        $nRet = ($nCenterV + $nNodeV + $nTimeV + $nRandV);
116 116
 
117 117
         //	...
118
-        if ( ! is_null( $arrData ) )
118
+        if (!is_null($arrData))
119 119
         {
120 120
             $arrData =
121 121
                 [
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
                 ];
127 127
         }
128 128
 
129
-        return intval( $nRet );
129
+        return intval($nRet);
130 130
     }
131 131
 
132 132
     /**
@@ -135,18 +135,18 @@  discard block
 block discarded – undo
135 135
      *	@param $nId int		64 bits unique id
136 136
      *	@return array		details about the id
137 137
      */
138
-    public function parseId( $nId )
138
+    public function parseId($nId)
139 139
     {
140
-        if ( ! is_numeric( $nId ) || $nId <= 0 )
140
+        if (!is_numeric($nId) || $nId <= 0)
141 141
         {
142 142
             return null;
143 143
         }
144 144
 
145 145
         //	...
146
-        $nCenter	= ( ( $nId & 0x00000000003E0000 ) >> 17 );
147
-        $nNode		= ( ( $nId & 0x000000000001F000 ) >> 12 );
148
-        $nTime		= ( ( $nId & 0x7FFFFFFFFFC00000 ) >> 22 );
149
-        $nRand		= ( ( $nId & 0x0000000000000FFF ) >> 0  );
146
+        $nCenter = (($nId & 0x00000000003E0000) >> 17);
147
+        $nNode		= (($nId & 0x000000000001F000) >> 12);
148
+        $nTime		= (($nId & 0x7FFFFFFFFFC00000) >> 22);
149
+        $nRand		= (($nId & 0x0000000000000FFF) >> 0);
150 150
 
151 151
         return
152 152
             [
@@ -163,20 +163,20 @@  discard block
 block discarded – undo
163 163
      *	@param $nVal int	64 bits unique id
164 164
      *	@return boolean		true or false
165 165
      */
166
-    public function isValidId( $nVal )
166
+    public function isValidId($nVal)
167 167
     {
168 168
         $bRet	= false;
169
-        $arrD	= $this->parseId( $nVal );
170
-        if ( is_array( $arrD ) &&
171
-            array_key_exists( 'center', $arrD ) &&
172
-            array_key_exists( 'node', $arrD ) &&
173
-            array_key_exists( 'time', $arrD ) &&
174
-            array_key_exists( 'rand', $arrD ) )
169
+        $arrD	= $this->parseId($nVal);
170
+        if (is_array($arrD) &&
171
+            array_key_exists('center', $arrD) &&
172
+            array_key_exists('node', $arrD) &&
173
+            array_key_exists('time', $arrD) &&
174
+            array_key_exists('rand', $arrD))
175 175
         {
176
-            if ( $this->isValidCenterId( $arrD[ 'center' ] ) &&
177
-                $this->isValidNodeId( $arrD[ 'node' ] ) &&
178
-                $this->isValidTime( $arrD[ 'time' ] ) &&
179
-                $this->isValidRand( $arrD[ 'rand' ] ) )
176
+            if ($this->isValidCenterId($arrD['center']) &&
177
+                $this->isValidNodeId($arrD['node']) &&
178
+                $this->isValidTime($arrD['time']) &&
179
+                $this->isValidRand($arrD['rand']))
180 180
             {
181 181
                 $bRet = true;
182 182
             }
@@ -190,36 +190,36 @@  discard block
 block discarded – undo
190 190
      * @param $nVal
191 191
      * @return bool
192 192
      */
193
-    public function isValidCenterId( $nVal )
193
+    public function isValidCenterId($nVal)
194 194
     {
195
-        return is_numeric( $nVal ) && ( $nVal >= 0 ) && ( $nVal <= 31 );
195
+        return is_numeric($nVal) && ($nVal >= 0) && ($nVal <= 31);
196 196
     }
197 197
 
198 198
     /**
199 199
      * @param $nVal
200 200
      * @return bool
201 201
      */
202
-    public function isValidNodeId( $nVal )
202
+    public function isValidNodeId($nVal)
203 203
     {
204
-        return is_numeric( $nVal ) && ( $nVal >= 0 ) && ( $nVal <= 31 );
204
+        return is_numeric($nVal) && ($nVal >= 0) && ($nVal <= 31);
205 205
     }
206 206
 
207 207
     /**
208 208
      * @param $nVal
209 209
      * @return bool
210 210
      */
211
-    public function isValidTime( $nVal )
211
+    public function isValidTime($nVal)
212 212
     {
213
-        return is_numeric( $nVal ) && ( $nVal >= 0 );
213
+        return is_numeric($nVal) && ($nVal >= 0);
214 214
     }
215 215
 
216 216
     /**
217 217
      * @param $nVal
218 218
      * @return bool
219 219
      */
220
-    public function isValidRand( $nVal )
220
+    public function isValidRand($nVal)
221 221
     {
222
-        return is_numeric( $nVal ) && ( $nVal >= 0 ) && ( $nVal <= 0xFFF );
222
+        return is_numeric($nVal) && ($nVal >= 0) && ($nVal <= 0xFFF);
223 223
     }
224 224
 
225 225
 
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
      */
231 231
     public function getUnixTimestamp()
232 232
     {
233
-        return floor( microtime( true ) * 1000 );
233
+        return floor(microtime(true) * 1000);
234 234
     }
235 235
 
236 236
     /**
@@ -240,6 +240,6 @@  discard block
 block discarded – undo
240 240
      */
241 241
     public function getEscapedTime()
242 242
     {
243
-        return intval( $this->getUnixTimestamp() - self::EPOCH_OFFSET );
243
+        return intval($this->getUnixTimestamp() - self::EPOCH_OFFSET);
244 244
     }
245 245
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -99,8 +99,7 @@
 block discarded – undo
99 99
         {
100 100
             //	use crc32 hash value instead of rand
101 101
             $nRand	= crc32( $sSource );
102
-        }
103
-        else
102
+        } else
104 103
         {
105 104
             //	0 ~ 4095
106 105
             $nRand	= rand( 0, 0xFFF );
Please login to merge, or discard this patch.