Passed
Push — master ( f7b499...13a894 )
by 世昌
01:48
created
nebula/component/debug/log/logger/FileLogger.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
      *
15 15
      * @var array
16 16
      */
17
-    protected $config  = [
17
+    protected $config = [
18 18
         'save-path' => './logs',
19 19
         'save-zip-path' => './logs/zip',
20 20
         'save-pack-path' => './logs/dump',
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
      */
53 53
     protected $latest;
54 54
 
55
-    public function __construct(array $config=[])
55
+    public function __construct(array $config = [])
56 56
     {
57 57
         $this->applyConfig($config);
58 58
         $temp = tmpfile();
59 59
         if ($temp === false) {
60
-            $this->tempname = $this->config['save-path'].'/log-'. microtime(true).'.tmp';
60
+            $this->tempname = $this->config['save-path'].'/log-'.microtime(true).'.tmp';
61 61
             $temp = fopen($this->tempname, 'w+');
62 62
         }
63 63
         if ($temp === false) {
@@ -68,12 +68,12 @@  discard block
 block discarded – undo
68 68
 
69 69
     protected function packLogFile()
70 70
     {
71
-        $logFile= $this->latest;
72
-        $path=preg_replace('/[\\\\]+/', '/', $this->config['save-zip-path'] .'/'.date('Y-m-d').'.zip');
71
+        $logFile = $this->latest;
72
+        $path = preg_replace('/[\\\\]+/', '/', $this->config['save-zip-path'].'/'.date('Y-m-d').'.zip');
73 73
         $zip = new ZipArchive;
74 74
         $res = $zip->open($path, ZipArchive::CREATE);
75 75
         if ($res === true) {
76
-            if ($zip->addFile($logFile, date('Y-m-d'). '-'. $zip->numFiles .'.log')) {
76
+            if ($zip->addFile($logFile, date('Y-m-d').'-'.$zip->numFiles.'.log')) {
77 77
                 array_push($this->removeFiles, $logFile);
78 78
             }
79 79
             $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->config['save-pack-path']));
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
             $zip->close();
86 86
         } else {
87 87
             if (is_file($logFile) && file_exists($logFile)) {
88
-                rename($logFile, $this->config['save-path'] . '/' . date('Y-m-d'). '-'. substr(md5_file($logFile), 0, 8).'.log');
88
+                rename($logFile, $this->config['save-path'].'/'.date('Y-m-d').'-'.substr(md5_file($logFile), 0, 8).'.log');
89 89
             }
90 90
         }
91 91
     }
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      */
109 109
     protected function checkSize():bool
110 110
     {
111
-        $logFile= $this->latest;
111
+        $logFile = $this->latest;
112 112
         if (file_exists($logFile)) {
113 113
             if (filesize($logFile) > $this->config['max-file-size']) {
114 114
                 return true;
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 
121 121
     public function log($level, string $message, array $context = [])
122 122
     {
123
-        if (LogLevel::compare($level, $this->config['log-level']) >=0) {
123
+        if (LogLevel::compare($level, $this->config['log-level']) >= 0) {
124 124
             $replace = [];
125 125
             $message = $this->interpolate($message, $context);
126 126
             $replace['%level%'] = $level;
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
     {
138 138
         $replace = [];
139 139
         foreach ($context as $key => $val) {
140
-            $replace['{' . $key . '}'] = $val;
140
+            $replace['{'.$key.'}'] = $val;
141 141
         }
142 142
         return strtr($message, $replace);
143 143
     }
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
     protected function rollLatest()
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.