Passed
Push — master ( 361274...bd53be )
by ma
02:35
created
src/StringTool.php 1 patch
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -80,22 +80,22 @@  discard block
 block discarded – undo
80 80
         $str = '';
81 81
         switch ($type) {
82 82
             case 0:
83
-                $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' . $addChars;
83
+                $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.$addChars;
84 84
                 break;
85 85
             case 1:
86 86
                 $chars = str_repeat('0123456789', 3);
87 87
                 break;
88 88
             case 2:
89
-                $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . $addChars;
89
+                $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.$addChars;
90 90
                 break;
91 91
             case 3:
92
-                $chars = 'abcdefghijklmnopqrstuvwxyz' . $addChars;
92
+                $chars = 'abcdefghijklmnopqrstuvwxyz'.$addChars;
93 93
                 break;
94 94
             case 4:
95
-                $chars = "们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书" . $addChars;
95
+                $chars = "们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书".$addChars;
96 96
                 break;
97 97
             default:
98
-                $chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789' . $addChars;
98
+                $chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'.$addChars;
99 99
                 break;
100 100
         }
101 101
         if ($length > 10) {
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
         if (!ctype_lower($value)) {
177 177
             $value = preg_replace('/\s+/u', '', ucwords($value));
178 178
 
179
-            $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value));
179
+            $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value));
180 180
         }
181 181
 
182 182
         return static::$snakeCache[$key][$delimiter] = $value;
@@ -259,16 +259,16 @@  discard block
 block discarded – undo
259 259
     static public function createChannelId($namespace = ''):string {
260 260
         static $guid = '';
261 261
         $uid = uniqid("", true);
262
-        $data = $namespace. md5(time() . mt_rand(1,1000000)).uniqid();
263
-        $hash = strtoupper(hash('ripemd128', $uid . $guid . md5($data)));
264
-        $guid = substr($hash, 0, 8) .
265
-            '-' .
266
-            substr($hash, 8, 4) .
267
-            '-' .
268
-            substr($hash, 12, 4) .
269
-            '-' .
270
-            substr($hash, 16, 4) .
271
-            '-' .
262
+        $data = $namespace.md5(time().mt_rand(1, 1000000)).uniqid();
263
+        $hash = strtoupper(hash('ripemd128', $uid.$guid.md5($data)));
264
+        $guid = substr($hash, 0, 8).
265
+            '-'.
266
+            substr($hash, 8, 4).
267
+            '-'.
268
+            substr($hash, 12, 4).
269
+            '-'.
270
+            substr($hash, 16, 4).
271
+            '-'.
272 272
             substr($hash, 20, 12);
273 273
         return $guid;
274 274
     }
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
      * @return string
282 282
      */
283 283
     static public function md5Bit16($str):string {
284
-        return strtoupper(substr(md5($str),8,16));
284
+        return strtoupper(substr(md5($str), 8, 16));
285 285
     }
286 286
 
287 287
     /**
@@ -291,15 +291,15 @@  discard block
 block discarded – undo
291 291
      * @return int
292 292
      */
293 293
     static public function millisecond($time = null) :int{
294
-        if(empty($time)){
294
+        if (empty($time)) {
295 295
             list($msec, $sec) = explode(' ', microtime());
296
-            $millisecond = (int)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
297
-        }elseif(is_numeric($time) && strlen((string)$time)==10){
298
-            $millisecond = (string)$time."000";
299
-        }else{
296
+            $millisecond = (int) sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
297
+        }elseif (is_numeric($time) && strlen((string) $time) == 10) {
298
+            $millisecond = (string) $time."000";
299
+        } else {
300 300
             $millisecond = strtotime($time)."000";
301 301
         }
302
-        return (int)$millisecond;
302
+        return (int) $millisecond;
303 303
     }
304 304
 
305 305
     /**
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
      * @param string $string
309 309
      * @return bool
310 310
      */
311
-    public static function isContainChinese($string=''):bool {
311
+    public static function isContainChinese($string = ''):bool {
312 312
         $result = preg_match('/[\x{4e00}-\x{9fa5}]/u', $string);
313 313
         return $result == 0 ? false : true;
314 314
     }
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
      * @param string $string
320 320
      * @return bool
321 321
      */
322
-    public static function isAllChinese($string=''):bool {
322
+    public static function isAllChinese($string = ''):bool {
323 323
         $result = preg_match('/^[\x{4e00}-\x{9fa5}]+$/u', $string);
324 324
         return $result == 0 ? false : true;
325 325
     }
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
      * @param string $string
332 332
      * @return bool
333 333
      */
334
-    public static function isMobile($string=''):bool {
334
+    public static function isMobile($string = ''):bool {
335 335
         if (!preg_match("/(^1[3|4|5|7|8][0-9]{9}$)/", $string)) {
336 336
             return false;
337 337
         }
@@ -346,9 +346,9 @@  discard block
 block discarded – undo
346 346
      * @param int $double   小数点保留位数 默认3位
347 347
      * @return string
348 348
      */
349
-    public static function sctonum($num, $double = 3){
350
-        if(false !== stripos($num, "e")){
351
-            $a = explode("e",strtolower($num));
349
+    public static function sctonum($num, $double = 3) {
350
+        if (false !== stripos($num, "e")) {
351
+            $a = explode("e", strtolower($num));
352 352
             return bcmul($a[0], bcpow(10, $a[1], $double), $double);
353 353
         }
354 354
         return $num;
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
      * @param string $to
363 363
      * @return array|false|string|string[]|null
364 364
      */
365
-    public static function autoCharset($string, $from='gbk', $to='utf-8') {
365
+    public static function autoCharset($string, $from = 'gbk', $to = 'utf-8') {
366 366
         $from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from;
367 367
         $to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to;
368 368
         if (strtoupper($from) === strtoupper($to) || empty($string) || (is_scalar($string) && !is_string($string))) {
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
      * @param $html
399 399
      * @return string
400 400
      */
401
-    public static function filterATag($html=''):string {
401
+    public static function filterATag($html = ''):string {
402 402
         return preg_replace("#<a[^>]*>(.*?)</a>#is", "$1", $html);
403 403
     }
404 404
 
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
      * @param $html
410 410
      * @return string
411 411
      */
412
-    public static function deleteATag($html=''):string {
412
+    public static function deleteATag($html = ''):string {
413 413
         return preg_replace("#<a[^>]*>(.*?)</a>#is", "", $html);
414 414
     }
415 415
 
@@ -421,36 +421,36 @@  discard block
 block discarded – undo
421 421
      * @param bool $is_timestamp   是否是时间戳
422 422
      * @return string
423 423
      */
424
-    public static function getTime($date,$is_timestamp=false):string {
425
-        if($is_timestamp === true){
424
+    public static function getTime($date, $is_timestamp = false):string {
425
+        if ($is_timestamp === true) {
426 426
             $time = $date;
427
-        }else{
428
-            $time = strtotime($date);//时间转换为时间戳
427
+        } else {
428
+            $time = strtotime($date); //时间转换为时间戳
429 429
         }
430 430
 
431
-        if($time >= time()){
431
+        if ($time >= time()) {
432 432
             return '刚刚';
433 433
         }
434 434
         $seconds = time() - $time;
435
-        if($seconds <= 60){
435
+        if ($seconds <= 60) {
436 436
             return '刚刚';
437 437
         }
438 438
         $minutes = intval($seconds / 60);
439
-        if($minutes <= 60){
439
+        if ($minutes <= 60) {
440 440
             return $minutes.'分钟前';
441 441
         }
442 442
         $hours = intval($minutes / 60);
443
-        if($hours <= 24){
443
+        if ($hours <= 24) {
444 444
             return $hours.'小时前';
445 445
         }
446 446
         $days = intval($hours / 24);
447
-        if($days <= 3){
447
+        if ($days <= 3) {
448 448
             return $days.'天前';
449 449
         }
450
-        if($days <= 365){
451
-            return date('m-d',/** @scrutinizer ignore-type */ $time);
450
+        if ($days <= 365) {
451
+            return date('m-d', /** @scrutinizer ignore-type */ $time);
452 452
         }
453
-        return date('Y-m-d',$time);
453
+        return date('Y-m-d', $time);
454 454
     }
455 455
 
456 456
     /**
@@ -464,11 +464,11 @@  discard block
 block discarded – undo
464 464
         $compress = '';
465 465
         foreach ($chunks as $c) {
466 466
             if (strtolower(substr($c, 0, 19)) == '<!--<nocompress>-->') {
467
-                $c        = substr($c, 19, strlen($c) - 19 - 20);
467
+                $c = substr($c, 19, strlen($c) - 19 - 20);
468 468
                 $compress .= $c;
469 469
                 continue;
470 470
             } elseif (strtolower(substr($c, 0, 12)) == '<nocompress>') {
471
-                $c        = substr($c, 12, strlen($c) - 12 - 13);
471
+                $c = substr($c, 12, strlen($c) - 12 - 13);
472 472
                 $compress .= $c;
473 473
                 continue;
474 474
             } elseif (strtolower(substr($c, 0, 4)) == '<pre' || strtolower(substr($c, 0, 9)) == '<textarea') {
@@ -516,14 +516,14 @@  discard block
 block discarded – undo
516 516
      * @return mixed
517 517
      */
518 518
     static public function htmlReplaceXcx(string $content):string {
519
-        $content = str_replace("\r\n","",$content);//出除回车和换行符
520
-        $content = preg_replace("/style=\".*?\"/si",'',$content);//style样式
521
-        $content = preg_replace(["/<strong.*?>/si", "/<\/strong>/si"],['<text class="wx-strong">','</text>'],$content);//strong
522
-        $content = preg_replace(["/<p.*?>/si", "/<\/p>/si"],['<view class="wx-p">','</view>'],$content);//p
523
-        $content = preg_replace(["/<a.*?>/si", "/<\/a>/si"],['<text class="wx-a">','</text>'],$content);//a
524
-        $content = preg_replace(["/<span.*?>/si", "/<\/span>/si"],['<text class="wx-span">','</text>'],$content);//span
525
-        $content = preg_replace(["/<h[1-6].*?>/si", "/<\/h[1-6]>/si"],['<view class="wx-h">','</view>'],$content);//h
526
-        $content = preg_replace("/<img.*?/si",'<image class="wx-img"',$content);//img
519
+        $content = str_replace("\r\n", "", $content); //出除回车和换行符
520
+        $content = preg_replace("/style=\".*?\"/si", '', $content); //style样式
521
+        $content = preg_replace(["/<strong.*?>/si", "/<\/strong>/si"], ['<text class="wx-strong">', '</text>'], $content); //strong
522
+        $content = preg_replace(["/<p.*?>/si", "/<\/p>/si"], ['<view class="wx-p">', '</view>'], $content); //p
523
+        $content = preg_replace(["/<a.*?>/si", "/<\/a>/si"], ['<text class="wx-a">', '</text>'], $content); //a
524
+        $content = preg_replace(["/<span.*?>/si", "/<\/span>/si"], ['<text class="wx-span">', '</text>'], $content); //span
525
+        $content = preg_replace(["/<h[1-6].*?>/si", "/<\/h[1-6]>/si"], ['<view class="wx-h">', '</view>'], $content); //h
526
+        $content = preg_replace("/<img.*?/si", '<image class="wx-img"', $content); //img
527 527
         return $content;
528 528
     }
529 529
 
@@ -535,8 +535,8 @@  discard block
 block discarded – undo
535 535
      * @return string
536 536
      */
537 537
     static public function pReplaceSpan(string $content):string {
538
-        $content = str_replace(["\r","\n","\t"],'',$content);
539
-        $content = preg_replace(["/<p/si", "/<\/p>/si"],['<span','</span><br>'],$content);//p
538
+        $content = str_replace(["\r", "\n", "\t"], '', $content);
539
+        $content = preg_replace(["/<p/si", "/<\/p>/si"], ['<span', '</span><br>'], $content); //p
540 540
         return $content;
541 541
     }
542 542
 
@@ -547,10 +547,10 @@  discard block
 block discarded – undo
547 547
      * @param  string $keyword
548 548
      * @return string
549 549
      */
550
-    static public function filterPunctuation($keyword){
551
-        $keyword = str_replace(["\r\n", "\r", "\n"," "," "], "", trim($keyword));//删除空格
552
-        $keyword = preg_replace('# #','',$keyword);
553
-        $keyword = preg_replace("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/",'',$keyword);
550
+    static public function filterPunctuation($keyword) {
551
+        $keyword = str_replace(["\r\n", "\r", "\n", " ", " "], "", trim($keyword)); //删除空格
552
+        $keyword = preg_replace('# #', '', $keyword);
553
+        $keyword = preg_replace("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/", '', $keyword);
554 554
         return $keyword;
555 555
     }
556 556
 
@@ -562,9 +562,9 @@  discard block
 block discarded – undo
562 562
      * @param string $allowable_tags
563 563
      * @return string
564 564
      */
565
-    static public function stripTags($content,$allowable_tags = '<font>'){
566
-        $content = strip_tags($content,$allowable_tags);//替换标签
567
-        $content = str_replace(["\r\n", "\r", "\n"," "], "", trim($content));//删除空格
565
+    static public function stripTags($content, $allowable_tags = '<font>') {
566
+        $content = strip_tags($content, $allowable_tags); //替换标签
567
+        $content = str_replace(["\r\n", "\r", "\n", " "], "", trim($content)); //删除空格
568 568
         return $content;
569 569
     }
570 570
 
Please login to merge, or discard this patch.