Passed
Push — master ( e61121...779b20 )
by 世昌
01:46
created
nebula/component/debug/log/logger/FileLogger.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
      *
16 16
      * @var array
17 17
      */
18
-    protected $config  = [
18
+    protected $config = [
19 19
         'save-path' => './logs',
20 20
         'save-zip-path' => './logs/zip',
21 21
         'save-pack-path' => './logs/dump',
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
      */
54 54
     protected $latest;
55 55
 
56
-    public function __construct(array $config=[])
56
+    public function __construct(array $config = [])
57 57
     {
58 58
         $this->applyConfig($config);
59 59
         $this->temp = tmpfile();
60 60
         if ($this->temp === false) {
61
-            $this->tempname = $this->config['save-path'].'/log-'. microtime(true).'.tmp';
61
+            $this->tempname = $this->config['save-path'].'/log-'.microtime(true).'.tmp';
62 62
             $this->temp = fopen($this->tempname, 'w+');
63 63
         }
64 64
         $this->latest = $this->config['save-path'].'/'.$this->config['file-name'];
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 
67 67
     protected function packLogFile()
68 68
     {
69
-        $logFile= $this->latest;
70
-        $path=preg_replace('/[\\\\]+/', '/', $this->config['save-zip-path'] .'/'.date('Y-m-d').'.zip');
69
+        $logFile = $this->latest;
70
+        $path = preg_replace('/[\\\\]+/', '/', $this->config['save-zip-path'].'/'.date('Y-m-d').'.zip');
71 71
         $zip = new ZipArchive;
72 72
         $res = $zip->open($path, ZipArchive::CREATE);
73 73
         if ($res === true) {
74
-            if ($zip->addFile($logFile, date('Y-m-d'). '-'. $zip->numFiles .'.log')) {
74
+            if ($zip->addFile($logFile, date('Y-m-d').'-'.$zip->numFiles.'.log')) {
75 75
                 array_push($this->removeFiles, $logFile);
76 76
             }
77 77
             $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->config['save-pack-path']));
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
             $zip->close();
84 84
         } else {
85 85
             if (is_file($logFile) && file_exists($logFile)) {
86
-                rename($logFile, $this->config['save-path'] . '/' . date('Y-m-d'). '-'. substr(md5_file($logFile), 0, 8).'.log');
86
+                rename($logFile, $this->config['save-path'].'/'.date('Y-m-d').'-'.substr(md5_file($logFile), 0, 8).'.log');
87 87
             }
88 88
         }
89 89
     }
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      */
107 107
     protected function checkSize():bool
108 108
     {
109
-        $logFile= $this->latest;
109
+        $logFile = $this->latest;
110 110
         if (file_exists($logFile)) {
111 111
             if (filesize($logFile) > $this->config['max-file-size']) {
112 112
                 return true;
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 
119 119
     public function log($level, string $message, array $context = [])
120 120
     {
121
-        if (LogLevel::compare($level, $this->config['log-level']) >=0) {
121
+        if (LogLevel::compare($level, $this->config['log-level']) >= 0) {
122 122
             $replace = [];
123 123
             $message = $this->interpolate($message, $context);
124 124
             $replace['%level%'] = $level;
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
     {
134 134
         $replace = [];
135 135
         foreach ($context as $key => $val) {
136
-            $replace['{' . $key . '}'] = $val;
136
+            $replace['{'.$key.'}'] = $val;
137 137
         }
138 138
         return strtr($message, $replace);
139 139
     }
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
     protected function rollLatest()
142 142
     {
143 143
         if (isset($this->latest)) {
144
-            $size=ftell($this->temp);
144
+            $size = ftell($this->temp);
145 145
             fseek($this->temp, 0);
146 146
             if ($size > 0) {
147
-                $body=fread($this->temp, $size);
147
+                $body = fread($this->temp, $size);
148 148
                 file_put_contents($this->latest, $body, FILE_APPEND);
149 149
             }
150 150
             fclose($this->temp);
Please login to merge, or discard this patch.
nebula/component/debug/attach/AttachTrait.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
      *
12 12
      * @var array
13 13
      */
14
-    protected $attribute=[];
14
+    protected $attribute = [];
15 15
     
16 16
     public function mergeAttribute(array $value)
17 17
     {
@@ -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,17 +34,17 @@  discard block
 block discarded – undo
34 34
 
35 35
     public function interpolate(string $message, array $context)
36 36
     {
37
-        list($attach, $replace) =  $this->analyse($context);
37
+        list($attach, $replace) = $this->analyse($context);
38 38
         foreach ($this->attribute as $key => $val) {
39
-            $replace['%' . $key . '%'] = $val;
39
+            $replace['%'.$key.'%'] = $val;
40 40
         }
41 41
         $message = strtr($message, $replace).PHP_EOL;
42 42
         foreach ($attach as $name => $value) {
43
-            $message.= $name.' = ';
43
+            $message .= $name.' = ';
44 44
             if ($value instanceof AttachValueInterface) {
45
-                $message.= $value->getLogAttach().PHP_EOL;
45
+                $message .= $value->getLogAttach().PHP_EOL;
46 46
             } else {
47
-                $message.= DumpTrait::parameterToString($value).PHP_EOL;
47
+                $message .= DumpTrait::parameterToString($value).PHP_EOL;
48 48
             }
49 49
         }
50 50
         return $message;
Please login to merge, or discard this patch.
nebula/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.
nebula/component/debug/Debug.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 
13 13
 class Debug implements LoggerInterface, LoggerAwareInterface, DumpInterface, AttachInterface
14 14
 {
15
-    use LoggerTrait,LoggerAwareTrait,DumpTrait,AttachTrait;
15
+    use LoggerTrait, LoggerAwareTrait, DumpTrait, AttachTrait;
16 16
 
17 17
     public function log(string $level, string $message, array $context = [])
18 18
     {
Please login to merge, or discard this patch.
public/dev.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use nebula\component\request\Request;
7 7
 use nebula\component\debug\log\logger\FileLogger;
8 8
 
9
-require_once __DIR__ .'/../vendor/autoload.php';
9
+require_once __DIR__.'/../vendor/autoload.php';
10 10
 
11 11
 $logger = new FileLogger(
12 12
     [
@@ -22,19 +22,19 @@  discard block
 block discarded – undo
22 22
 $request = Request::buildFromServer();
23 23
 $request->apply(true);
24 24
 $debug->debug('request apply true', [
25
-    'request' => $request ,
25
+    'request' => $request,
26 26
     'exception' => new Exception('test exception')
27 27
 ]);
28 28
 
29 29
 $debug->debug('request  getBasicURI {url}', ['url' => $request->getBasicURI()]);
30 30
 
31
-function formatBytes(int $bytes, int $precision=0)
31
+function formatBytes(int $bytes, int $precision = 0)
32 32
 {
33
-    $human= ['B', 'KB', 'MB', 'GB', 'TB'];
33
+    $human = ['B', 'KB', 'MB', 'GB', 'TB'];
34 34
     $bytes = max($bytes, 0);
35
-    $pow = floor(($bytes?log($bytes):0)/log(1024));
36
-    $pos = min($pow, count($human)-1);
37
-    $bytes /= (1 << (10* $pos));
35
+    $pow = floor(($bytes ?log($bytes) : 0) / log(1024));
36
+    $pos = min($pow, count($human) - 1);
37
+    $bytes /= (1 << (10 * $pos));
38 38
     return round($bytes, $precision).' '.$human[$pos];
39 39
 }
40 40
 
Please login to merge, or discard this patch.