Passed
Push — master ( a51a38...e61121 )
by 世昌
01:50
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
     }
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
         }
146 146
  
147 147
         if (isset($this->latest)) {
148
-            $size=ftell($this->temp);
148
+            $size = ftell($this->temp);
149 149
             fseek($this->temp, 0);
150 150
             if ($size > 0) {
151
-                $body=fread($this->temp, $size);
151
+                $body = fread($this->temp, $size);
152 152
                 file_put_contents($this->latest, $body, FILE_APPEND);
153 153
             }
154 154
             fclose($this->temp);
Please login to merge, or discard this patch.
nebula/component/debug/attach/AttachTrait.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
         $replace = [];
31 31
         foreach ($context as $key => $val) {
32 32
             if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) {
33
-                $replace['{' . $key . '}'] = $val;
33
+                $replace['{'.$key.'}'] = $val;
34 34
             } else {
35 35
                 $this->attach[$key] = $val;
36 36
             }
@@ -40,19 +40,19 @@  discard block
 block discarded – undo
40 40
 
41 41
     public function interpolate(string $message, array $context)
42 42
     {
43
-        $replace =  $this->analyse($context);
43
+        $replace = $this->analyse($context);
44 44
         foreach ($this->attribute as $key => $val) {
45
-            $replace['%' . $key . '%'] = $val;
45
+            $replace['%'.$key.'%'] = $val;
46 46
         }
47 47
         $message = strtr($message, $replace);
48 48
         foreach ($this->attach as $name => $value) {
49
-            $message.=PHP_EOL.$name.'<' . get_class($val).'>'.PHP_EOL;
49
+            $message .= PHP_EOL.$name.'<'.get_class($val).'>'.PHP_EOL;
50 50
             if ($value instanceof AttachValueInterface) {
51
-                $message.= $value->getLogAttach().PHP_EOL;
51
+                $message .= $value->getLogAttach().PHP_EOL;
52 52
             } elseif ($value instanceof \Exception) {
53
-                $message.= DumpTrait::dumpException($value).PHP_EOL;
53
+                $message .= DumpTrait::dumpException($value).PHP_EOL;
54 54
             } else {
55
-                $message.= DumpTrait::parameterToString($value).PHP_EOL;
55
+                $message .= DumpTrait::parameterToString($value).PHP_EOL;
56 56
             }
57 57
         }
58 58
         return $message;
Please login to merge, or discard this patch.
nebula/component/debug/attach/DumpTrait.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
         if ($deep > 0) {
17 17
             $vars = get_class_vars($objectName);
18 18
             foreach ($vars as $key => $value) {
19
-                $parameterString.=static::valueToString($key, $value, $deep);
19
+                $parameterString .= static::valueToString($key, $value, $deep);
20 20
             }
21 21
         } else {
22 22
             $parameterString = '...';
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
         $parameterString = '';
30 30
         if ($deep > 0) {
31 31
             foreach ($object as $key => $value) {
32
-                $parameterString.=static::valueToString($key, $value, $deep);
32
+                $parameterString .= static::valueToString($key, $value, $deep);
33 33
             }
34 34
         } else {
35 35
             $parameterString = '...';
@@ -48,13 +48,13 @@  discard block
 block discarded – undo
48 48
     protected static function valueToString(string $key, $value, int $deep):string
49 49
     {
50 50
         if (is_string($value) && strlen($value) > static::$attachStringLength) {
51
-            return  $key.'='.json_encode(substr($value, 0, static::$attachStringShowLength), JSON_UNESCAPED_UNICODE) .'...,';
51
+            return  $key.'='.json_encode(substr($value, 0, static::$attachStringShowLength), JSON_UNESCAPED_UNICODE).'...,';
52 52
         } else {
53
-            return $key.'='.self::parameterToString($value, $deep-1) .',';
53
+            return $key.'='.self::parameterToString($value, $deep - 1).',';
54 54
         }
55 55
     }
56 56
 
57
-    public static function parameterToString($object, int $deep=2)
57
+    public static function parameterToString($object, int $deep = 2)
58 58
     {
59 59
         if (is_null($object)) {
60 60
             return 'NULL';
@@ -66,16 +66,16 @@  discard block
 block discarded – undo
66 66
         return $object;
67 67
     }
68 68
 
69
-    public static function dumpTrace(array $backtrace, bool $str=true, string $perfix='')
69
+    public static function dumpTrace(array $backtrace, bool $str = true, string $perfix = '')
70 70
     {
71
-        $tracesConsole=[];
71
+        $tracesConsole = [];
72 72
         foreach ($backtrace as $trace) {
73
-            $tracesConsole[]=static::buildTraceLine($trace);
73
+            $tracesConsole[] = static::buildTraceLine($trace);
74 74
         }
75 75
         if ($str) {
76
-            $str='';
76
+            $str = '';
77 77
             foreach ($tracesConsole as $trace_info) {
78
-                $str.=$perfix.preg_replace('/\n/', "\n".$perfix."\t", $trace_info).PHP_EOL;
78
+                $str .= $perfix.preg_replace('/\n/', "\n".$perfix."\t", $trace_info).PHP_EOL;
79 79
             }
80 80
             return $str;
81 81
         }
@@ -93,22 +93,22 @@  discard block
 block discarded – undo
93 93
         } else {
94 94
             $function = $trace['function'];
95 95
         }
96
-        $argsDump='';
96
+        $argsDump = '';
97 97
         if (!empty($trace['args'])) {
98 98
             foreach ($trace['args'] as $arg) {
99
-                $argsDump.= self::parameterToString($arg) .',';
99
+                $argsDump .= self::parameterToString($arg).',';
100 100
             }
101 101
             $argsDump = rtrim($argsDump, ',');
102 102
         }
103
-        $line.=' '.$function.'('.$argsDump.')';
103
+        $line .= ' '.$function.'('.$argsDump.')';
104 104
         return $line;
105 105
     }
106 106
 
107 107
     public static function dumpException(\Exception $e)
108 108
     {
109
-        $dump = $e->getMessage() .PHP_EOL;
110
-        $dump.= 'At: ' . $e->getFile().':'.$e->getLine().PHP_EOL;
111
-        $dump.= static::printTrace($e->getTrace());
109
+        $dump = $e->getMessage().PHP_EOL;
110
+        $dump .= 'At: '.$e->getFile().':'.$e->getLine().PHP_EOL;
111
+        $dump .= static::printTrace($e->getTrace());
112 112
         return $dump;
113 113
     }
114 114
 }
Please login to merge, or discard this patch.
nebula/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.
nebula/component/debug/Debug.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,9 +10,9 @@
 block discarded – undo
10 10
 use nebula\component\debug\attach\AttachInterface;
11 11
 use nebula\component\debug\log\LoggerAwareInterface;
12 12
 
13
-class Debug implements LoggerInterface, LoggerAwareInterface,DumpInterface, AttachInterface
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   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use nebula\component\request\Request;
6 6
 use nebula\component\debug\log\logger\FileLogger;
7 7
 
8
-require_once __DIR__ .'/../vendor/autoload.php';
8
+require_once __DIR__.'/../vendor/autoload.php';
9 9
 
10 10
 $logger = new FileLogger(
11 11
     [
@@ -20,13 +20,13 @@  discard block
 block discarded – undo
20 20
 $logger->debug('request apply true');
21 21
 $logger->debug('request  getBasicURI {url}', ['url' => $request->getBasicURI()]);
22 22
 
23
-function formatBytes(int $bytes, int $precision=0)
23
+function formatBytes(int $bytes, int $precision = 0)
24 24
 {
25
-    $human= ['B', 'KB', 'MB', 'GB', 'TB'];
25
+    $human = ['B', 'KB', 'MB', 'GB', 'TB'];
26 26
     $bytes = max($bytes, 0);
27
-    $pow = floor(($bytes?log($bytes):0)/log(1024));
28
-    $pos = min($pow, count($human)-1);
29
-    $bytes /= (1 << (10* $pos));
27
+    $pow = floor(($bytes ?log($bytes) : 0) / log(1024));
28
+    $pos = min($pow, count($human) - 1);
29
+    $bytes /= (1 << (10 * $pos));
30 30
     return round($bytes, $precision).' '.$human[$pos];
31 31
 }
32 32
 
Please login to merge, or discard this patch.