Passed
Push — master ( c547da...5d2787 )
by 世昌
02:10 queued 15s
created
suda/src/component/route/uri/UriMatcher.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
      * @param boolean $ignoreCase
47 47
      * @return array|null
48 48
      */
49
-    public function match(string $url, bool $ignoreCase = true):?array
49
+    public function match(string $url, bool $ignoreCase = true): ?array
50 50
     {
51
-        $match = '#^'. $this->match.'$#'. ($ignoreCase?'i':'');
51
+        $match = '#^'.$this->match.'$#'.($ignoreCase ? 'i' : '');
52 52
         $parameter = [];
53 53
         if (preg_match($match, $url, $parameter, PREG_UNMATCHED_AS_NULL) > 0) {
54 54
             return array_slice($parameter, 1);
@@ -72,12 +72,12 @@  discard block
 block discarded – undo
72 72
             } else {
73 73
                 $value = $parameter->unpackValue($match);
74 74
             }
75
-            $parameters[$parameter->getIndexName()] =  $value;
75
+            $parameters[$parameter->getIndexName()] = $value;
76 76
         }
77 77
         return $parameters;
78 78
     }
79 79
 
80
-    public function getParameter(string $name):?Parameter
80
+    public function getParameter(string $name): ?Parameter
81 81
     {
82 82
         foreach ($this->parameter as $parameter) {
83 83
             if ($parameter->getIndexName() === $name) {
Please login to merge, or discard this patch.
suda/src/component/route/uri/MatcherHelper.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -26,18 +26,18 @@  discard block
 block discarded – undo
26 26
         // 参数
27 27
         $parameters = [];
28 28
         // 转义正则
29
-        $url=preg_replace('/([\/\.\\\\\+\(\^\)\$\!\<\>\-\?\*])/', '\\\\$1', $uri);
29
+        $url = preg_replace('/([\/\.\\\\\+\(\^\)\$\!\<\>\-\?\*])/', '\\\\$1', $uri);
30 30
         // 添加忽略
31
-        $url=preg_replace('/(\[)([^\[\]]+)(?(1)\])/', '(?:$2)?', $url);
31
+        $url = preg_replace('/(\[)([^\[\]]+)(?(1)\])/', '(?:$2)?', $url);
32 32
         // 添加 * ? 匹配
33
-        $url=str_replace(['\*','\?'], ['[^/]*?','[^/]'], $url);
33
+        $url = str_replace(['\*', '\?'], ['[^/]*?', '[^/]'], $url);
34 34
         // 编译页面参数
35
-        $url=preg_replace_callback('/\{(\w+)(?:\:([^}]+?))?\}/', function ($match) use (&$parameters) {
35
+        $url = preg_replace_callback('/\{(\w+)(?:\:([^}]+?))?\}/', function($match) use (&$parameters) {
36 36
             $name = $match[1];
37 37
             $type = 'string';
38 38
             $extra = '';
39 39
             if (isset($match[2])) {
40
-                if (strpos($match[2], '=')!==false) {
40
+                if (strpos($match[2], '=') !== false) {
41 41
                     list($type, $extra) = \explode('=', $match[2]);
42 42
                 } else {
43 43
                     $type = $match[2];
@@ -56,16 +56,16 @@  discard block
 block discarded – undo
56 56
 
57 57
     public static function buildUri(UriMatcher $matcher, array $parameter, bool $allowQuery = true):string
58 58
     {
59
-        $uri =  $matcher->getUri();
59
+        $uri = $matcher->getUri();
60 60
         // 拆分参数
61 61
         list($mapper, $query) = static::analyseParameter($matcher, $parameter);
62 62
         // for * ?
63
-        $url=\str_replace(['*','?'], ['','-'], $uri);
63
+        $url = \str_replace(['*', '?'], ['', '-'], $uri);
64 64
         // for ignore value
65
-        $url=preg_replace_callback('/\[(.+?)\]/', function ($match) use ($matcher, $parameter, $mapper) {
65
+        $url = preg_replace_callback('/\[(.+?)\]/', function($match) use ($matcher, $parameter, $mapper) {
66 66
             if (preg_match('/\{(\w+).+?\}/', $match[1])) {
67 67
                 $count = 0;
68
-                $subUrl= static::replaceParameter($match[1], $matcher, $parameter, $mapper, $count);
68
+                $subUrl = static::replaceParameter($match[1], $matcher, $parameter, $mapper, $count);
69 69
                 if ($count > 0) {
70 70
                     return $subUrl;
71 71
                 }
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
             return '';
74 74
         }, $url);
75 75
  
76
-        $url= static::replaceParameter($url, $matcher, $parameter, $mapper);
76
+        $url = static::replaceParameter($url, $matcher, $parameter, $mapper);
77 77
 
78 78
         if (count($query) && $allowQuery) {
79 79
             return $url.'?'.http_build_query($query, 'v', '&', PHP_QUERY_RFC3986);
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
         return [$mapper, $query];
98 98
     }
99 99
 
100
-    protected static function replaceParameter(string $input, UriMatcher $matcher, array $parameter, array $mapper, ?int &$count=null)
100
+    protected static function replaceParameter(string $input, UriMatcher $matcher, array $parameter, array $mapper, ?int &$count = null)
101 101
     {
102
-        return preg_replace_callback('/\{(\w+).+?\}/', function ($match) use ($matcher, $parameter, $mapper) {
102
+        return preg_replace_callback('/\{(\w+).+?\}/', function($match) use ($matcher, $parameter, $mapper) {
103 103
             if (\array_key_exists($match[1], $mapper)) {
104 104
                 return $mapper[$match[1]]->packValue($parameter[$match[1]]);
105 105
             }
Please login to merge, or discard this patch.
suda/src/component/route/RouteCollection.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
      *
24 24
      * @param RouteMatcher[] $collection
25 25
      */
26
-    public function __construct(array $collection=[])
26
+    public function __construct(array $collection = [])
27 27
     {
28 28
         $this->mergeArray($collection);
29 29
     }
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      * @param array $collection
35 35
      * @return void
36 36
      */
37
-    public function mergeArray(array $collection=[])
37
+    public function mergeArray(array $collection = [])
38 38
     {
39 39
         $this->collection = array_merge($this->collection, $collection);
40 40
     }
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
      * @param string $name
69 69
      * @return RouteMatcher|null
70 70
      */
71
-    public function get(string $name):?RouteMatcher
71
+    public function get(string $name): ?RouteMatcher
72 72
     {
73 73
         return $this->collection[$name] ?? null;
74 74
     }
Please login to merge, or discard this patch.
suda/src/component/route/RouteMatcher.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -39,9 +39,9 @@  discard block
 block discarded – undo
39 39
     protected $matcher;
40 40
     
41 41
 
42
-    public function __construct(array $methods, string $uri, array $attribute=[])
42
+    public function __construct(array $methods, string $uri, array $attribute = [])
43 43
     {
44
-        array_walk($methods, function ($value) {
44
+        array_walk($methods, function($value) {
45 45
             return strtoupper($value);
46 46
         });
47 47
         $this->methods = $methods;
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      * @param RequestInterface $request
158 158
      * @return array|null
159 159
      */
160
-    public function match(RequestInterface $request):?array
160
+    public function match(RequestInterface $request): ?array
161 161
     {
162 162
         if (count($this->methods) > 0 && !\in_array($request->getMethod(), $this->methods)) {
163 163
             return null;
Please login to merge, or discard this patch.
suda/src/component/debug/attach/DumpTrait.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@  discard block
 block discarded – undo
15 15
         if ($deep > 0) {
16 16
             $vars = get_class_vars($objectName);
17 17
             foreach ($vars as $key => $value) {
18
-                $parameterString.=static::valueToString($key, $value, $deep);
18
+                $parameterString .= static::valueToString($key, $value, $deep);
19 19
             }
20
-            $parameterString.= static::objectGetter($objectName, $object, $deep);
20
+            $parameterString .= static::objectGetter($objectName, $object, $deep);
21 21
         } else {
22 22
             $parameterString = '...';
23 23
         }
@@ -27,13 +27,13 @@  discard block
 block discarded – undo
27 27
     protected static function objectGetter(string $objectName, object $object, int $deep)
28 28
     {
29 29
         $methods = get_class_methods($objectName);
30
-        $parameterString ='';
30
+        $parameterString = '';
31 31
         foreach ($methods as $method) {
32 32
             if (strpos($method, 'get') === 0) {
33 33
                 $methodRef = new \ReflectionMethod($object, $method);
34 34
                 $ignore = \preg_match('/@ignore(-d|D)ump/i', $methodRef->getDocComment()??'') > 0;
35 35
                 if (count($methodRef->getParameters()) === 0 && !$ignore) {
36
-                    $parameterString.=static::valueToString($method.'()', $object->$method(), $deep);
36
+                    $parameterString .= static::valueToString($method.'()', $object->$method(), $deep);
37 37
                 }
38 38
             }
39 39
         }
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
         $parameterString = '';
46 46
         if ($deep > 0) {
47 47
             foreach ($array as $key => $value) {
48
-                $parameterString.=static::valueToString($key, $value, $deep);
48
+                $parameterString .= static::valueToString($key, $value, $deep);
49 49
             }
50 50
         } else {
51 51
             $parameterString = '...';
@@ -64,15 +64,15 @@  discard block
 block discarded – undo
64 64
     protected static function valueToString(string $key, $value, int $deep):string
65 65
     {
66 66
         if (is_string($value) && strlen($value) > static::$dumpStringLength) {
67
-            return  $key.'='.json_encode(substr($value, 0, static::$dumpStringLength), JSON_UNESCAPED_UNICODE) .'... ,';
67
+            return  $key.'='.json_encode(substr($value, 0, static::$dumpStringLength), JSON_UNESCAPED_UNICODE).'... ,';
68 68
         } elseif (is_bool($value)) {
69 69
             return $key.'='.($value ? 'true' : 'false').' ,';
70 70
         } else {
71
-            return $key.'='.self::parameterToString($value, $deep-1) .' ,';
71
+            return $key.'='.self::parameterToString($value, $deep - 1).' ,';
72 72
         }
73 73
     }
74 74
 
75
-    public static function parameterToString($object, int $deep=2)
75
+    public static function parameterToString($object, int $deep = 2)
76 76
     {
77 77
         if (is_null($object)) {
78 78
             return 'NULL';
@@ -86,16 +86,16 @@  discard block
 block discarded – undo
86 86
         return $object;
87 87
     }
88 88
 
89
-    public static function dumpTrace(array $backtrace, bool $str=true, string $perfix='')
89
+    public static function dumpTrace(array $backtrace, bool $str = true, string $perfix = '')
90 90
     {
91
-        $tracesConsole=[];
91
+        $tracesConsole = [];
92 92
         foreach ($backtrace as $trace) {
93
-            $tracesConsole[]=static::buildTraceLine($trace);
93
+            $tracesConsole[] = static::buildTraceLine($trace);
94 94
         }
95 95
         if ($str) {
96
-            $str='';
96
+            $str = '';
97 97
             foreach ($tracesConsole as $trace_info) {
98
-                $str.=$perfix.preg_replace('/\n/', "\n".$perfix."\t", $trace_info).PHP_EOL;
98
+                $str .= $perfix.preg_replace('/\n/', "\n".$perfix."\t", $trace_info).PHP_EOL;
99 99
             }
100 100
             return $str;
101 101
         }
@@ -113,22 +113,22 @@  discard block
 block discarded – undo
113 113
         } else {
114 114
             $function = $trace['function'];
115 115
         }
116
-        $argsDump='';
116
+        $argsDump = '';
117 117
         if (!empty($trace['args'])) {
118 118
             foreach ($trace['args'] as $arg) {
119
-                $argsDump.= self::parameterToString($arg) .',';
119
+                $argsDump .= self::parameterToString($arg).',';
120 120
             }
121 121
             $argsDump = rtrim($argsDump, ',');
122 122
         }
123
-        $line.=' '.$function.'('.$argsDump.')';
123
+        $line .= ' '.$function.'('.$argsDump.')';
124 124
         return $line;
125 125
     }
126 126
 
127 127
     public static function dumpException(\Exception $e)
128 128
     {
129
-        $dump = get_class($e).':'. $e->getMessage() .PHP_EOL;
130
-        $dump.= 'At: ' . $e->getFile().':'.$e->getLine().PHP_EOL;
131
-        $dump.= static::dumpTrace($e->getTrace());
129
+        $dump = get_class($e).':'.$e->getMessage().PHP_EOL;
130
+        $dump .= 'At: '.$e->getFile().':'.$e->getLine().PHP_EOL;
131
+        $dump .= static::dumpTrace($e->getTrace());
132 132
         return $dump;
133 133
     }
134 134
 }
Please login to merge, or discard this patch.
suda/src/component/debug/attach/DumpInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
  */
7 7
 interface DumpInterface 
8 8
 {
9
-    public static function parameterToString($object, int $deep=2);
9
+    public static function parameterToString($object, int $deep = 2);
10 10
     public static function dumpException(\Exception $e);
11
-    public static function dumpTrace(array $backtrace, bool $str=true, string $perfix='');
11
+    public static function dumpTrace(array $backtrace, bool $str = true, string $perfix = '');
12 12
 }
Please login to merge, or discard this patch.
suda/src/component/debug/attach/AttachTrait.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@  discard block
 block discarded – undo
11 11
      *
12 12
      * @var array
13 13
      */
14
-    protected $attribute=[];
14
+    protected $attribute = [];
15 15
     
16
-    public function addAttribute(string $name , $value)
16
+    public function addAttribute(string $name, $value)
17 17
     {
18 18
         $this->attribute[$name] = $value;
19 19
     }
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
     protected function analyse(array $context)
22 22
     {
23 23
         $replace = [];
24
-        $attach  =[] ;
24
+        $attach  = [];
25 25
         foreach ($context as $key => $val) {
26
-            if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString')) && ! $val instanceof \Exception) {
27
-                $replace['{' . $key . '}'] = $val;
26
+            if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString')) && !$val instanceof \Exception) {
27
+                $replace['{'.$key.'}'] = $val;
28 28
             } else {
29 29
                 $attach[$key] = $val;
30 30
             }
@@ -34,19 +34,19 @@  discard block
 block discarded – undo
34 34
 
35 35
     public function interpolate(string $message, array $context, array $attribute)
36 36
     {
37
-        list($attach, $replace) =  $this->analyse($context);
37
+        list($attach, $replace) = $this->analyse($context);
38 38
         $attribute = array_merge($this->attribute, $attribute);
39 39
         foreach ($attribute as $key => $val) {
40
-            $replace['%' . $key . '%'] = $val;
40
+            $replace['%'.$key.'%'] = $val;
41 41
         }
42 42
         $message = strtr($message, $replace);
43 43
         $attachInfo = '';
44 44
         foreach ($attach as $name => $value) {
45 45
             $attachInfo = $name.' = ';
46 46
             if ($value instanceof AttachValueInterface) {
47
-                $attachInfo.= $value->getLogAttach().PHP_EOL;
47
+                $attachInfo .= $value->getLogAttach().PHP_EOL;
48 48
             } else {
49
-                $attachInfo.= DumpTrait::parameterToString($value).PHP_EOL;
49
+                $attachInfo .= DumpTrait::parameterToString($value).PHP_EOL;
50 50
             }
51 51
         }
52 52
         if (strlen($attachInfo) > 0) {
Please login to merge, or discard this patch.
suda/src/component/debug/ConfigTrait.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
     }
21 21
     public function getConfig(string $name) {
22 22
         $defaultConfig = $this->getDefaultConfig();
23
-        return $this->config[$name] ?? $defaultConfig[$name];;
23
+        return $this->config[$name] ?? $defaultConfig[$name]; ;
24 24
     }
25 25
 
26 26
     abstract public function getDefaultConfig():array;
Please login to merge, or discard this patch.
suda/src/component/debug/Debug.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
 class Debug implements LoggerInterface, LoggerAwareInterface, DumpInterface, AttachInterface, ConfigInterface
18 18
 {
19
-    use LoggerTrait,LoggerAwareTrait,DumpTrait,AttachTrait,ConfigTrait;
19
+    use LoggerTrait, LoggerAwareTrait, DumpTrait, AttachTrait, ConfigTrait;
20 20
 
21 21
     /**
22 22
      * 时间记录
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
     {
52 52
         $replace = [];
53 53
         foreach ($context as $key => $val) {
54
-            $replace['{' . $key . '}'] = $val;
54
+            $replace['{'.$key.'}'] = $val;
55 55
         }
56 56
         return strtr($message, $replace);
57 57
     }
@@ -67,26 +67,26 @@  discard block
 block discarded – undo
67 67
         return $attribute;
68 68
     }
69 69
 
70
-    protected static function formatBytes(int $bytes, int $precision=0)
70
+    protected static function formatBytes(int $bytes, int $precision = 0)
71 71
     {
72
-        $human= ['B', 'KB', 'MB', 'GB', 'TB'];
72
+        $human = ['B', 'KB', 'MB', 'GB', 'TB'];
73 73
         $bytes = max($bytes, 0);
74
-        $pow = floor(($bytes?log($bytes):0)/log(1024));
75
-        $pos = min($pow, count($human)-1);
76
-        $bytes /= (1 << (10* $pos));
74
+        $pow = floor(($bytes ?log($bytes) : 0) / log(1024));
75
+        $pos = min($pow, count($human) - 1);
76
+        $bytes /= (1 << (10 * $pos));
77 77
         return round($bytes, $precision).' '.$human[$pos];
78 78
     }
79 79
 
80
-    public function time(string $name, string $type= LogLevel::INFO)
80
+    public function time(string $name, string $type = LogLevel::INFO)
81 81
     {
82
-        $this->timeRecord[$name]=['time'=>microtime(true),'level'=>$type];
82
+        $this->timeRecord[$name] = ['time'=>microtime(true), 'level'=>$type];
83 83
     }
84 84
 
85 85
     public function timeEnd(string $name)
86 86
     {
87 87
         if (\array_key_exists($name, $this->timeRecord)) {
88
-            $pass=microtime(true)-$this->timeRecord[$name]['time'];
89
-            $this->log($this->timeRecord[$name]['level'], 'process cost '. $name.' '. number_format($pass, 5).'s');
88
+            $pass = microtime(true) - $this->timeRecord[$name]['time'];
89
+            $this->log($this->timeRecord[$name]['level'], 'process cost '.$name.' '.number_format($pass, 5).'s');
90 90
             return $pass;
91 91
         }
92 92
         return 0;
Please login to merge, or discard this patch.