Passed
Push — master ( e1b8c4...ea4361 )
by 世昌
01:52
created
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.
suda/src/component/debug/ConfigInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace suda\component\debug;
3 3
 
4
-interface ConfigInterface  {
4
+interface ConfigInterface {
5 5
     public function applyConfig(array $config);
6 6
 }
Please login to merge, or discard this patch.
suda/src/component/debug/log/logger/FileLogger.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -46,12 +46,12 @@  discard block
 block discarded – undo
46 46
      * @throws FileLoggerException
47 47
      * @param array $config
48 48
      */
49
-    public function __construct(array $config=[])
49
+    public function __construct(array $config = [])
50 50
     {
51 51
         $this->applyConfig($config);
52 52
         $temp = tmpfile();
53 53
         if ($temp === false) {
54
-            $this->tempname = $this->getConfig('save-path').'/log-'. microtime(true).'.tmp';
54
+            $this->tempname = $this->getConfig('save-path').'/log-'.microtime(true).'.tmp';
55 55
             $temp = fopen($this->tempname, 'w+');
56 56
         }
57 57
         if ($temp !== false) {
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             throw new FileLoggerException(__CLASS__.':'.sprintf('cannot create log file'));
61 61
         }
62 62
         $this->latest = $this->getConfig('save-path').'/'.$this->getConfig('file-name');
63
-        \register_shutdown_function([$this,'save']);
63
+        \register_shutdown_function([$this, 'save']);
64 64
     }
65 65
 
66 66
     public function getDefaultConfig():array
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
     
79 79
     protected function packLogFile()
80 80
     {
81
-        $logFile= $this->latest;
82
-        $path=preg_replace('/[\\\\]+/', '/', $this->getConfig('save-zip-path') .'/'.date('Y-m-d').'.zip');
81
+        $logFile = $this->latest;
82
+        $path = preg_replace('/[\\\\]+/', '/', $this->getConfig('save-zip-path').'/'.date('Y-m-d').'.zip');
83 83
         $zip = new ZipArchive;
84 84
         $res = $zip->open($path, ZipArchive::CREATE);
85 85
         if ($res === true) {
86
-            if ($zip->addFile($logFile, date('Y-m-d'). '-'. $zip->numFiles .'.log')) {
86
+            if ($zip->addFile($logFile, date('Y-m-d').'-'.$zip->numFiles.'.log')) {
87 87
                 array_push($this->removeFiles, $logFile);
88 88
             }
89 89
             if (\is_dir($this->getConfig('save-pack-path'))) {
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
             $zip->close();
98 98
         } else {
99 99
             if (is_file($logFile) && file_exists($logFile)) {
100
-                rename($logFile, $this->getConfig('save-path') . '/' . date('Y-m-d'). '-'. substr(md5_file($logFile), 0, 8).'.log');
100
+                rename($logFile, $this->getConfig('save-path').'/'.date('Y-m-d').'-'.substr(md5_file($logFile), 0, 8).'.log');
101 101
             }
102 102
         }
103 103
     }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
      */
110 110
     protected function checkSize():bool
111 111
     {
112
-        $logFile= $this->latest;
112
+        $logFile = $this->latest;
113 113
         if (file_exists($logFile)) {
114 114
             if (filesize($logFile) > $this->getConfig('max-file-size')) {
115 115
                 return true;
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 
122 122
     public function log($level, string $message, array $context = [])
123 123
     {
124
-        if (LogLevel::compare($level, $this->getConfig('log-level')) >=0) {
124
+        if (LogLevel::compare($level, $this->getConfig('log-level')) >= 0) {
125 125
             $replace = [];
126 126
             $message = $this->interpolate($message, $context);
127 127
             $replace['%level%'] = $level;
@@ -134,10 +134,10 @@  discard block
 block discarded – undo
134 134
     protected function rollLatest()
135 135
     {
136 136
         if (isset($this->latest)) {
137
-            $size=ftell($this->temp);
137
+            $size = ftell($this->temp);
138 138
             fseek($this->temp, 0);
139 139
             if ($size > 0) {
140
-                $body=fread($this->temp, $size);
140
+                $body = fread($this->temp, $size);
141 141
                 file_put_contents($this->latest, $body, FILE_APPEND);
142 142
             }
143 143
             fclose($this->temp);
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
             } elseif (is_null($val)) {
175 175
                 $val = 'null';
176 176
             }
177
-            $replace['{' . $key . '}'] = $val;
177
+            $replace['{'.$key.'}'] = $val;
178 178
         }
179 179
         return strtr($message, $replace);
180 180
     }
Please login to merge, or discard this patch.