Passed
Push — master ( 729fd7...f34cda )
by 世昌
01:58
created
nebula/src/application/cache/FileCache.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -31,19 +31,19 @@  discard block
 block discarded – undo
31 31
      * @param int $expire 过期时间
32 32
      * @return bool
33 33
      */
34
-    public function set(string $name, $value, int $expire=null):bool
34
+    public function set(string $name, $value, int $expire = null):bool
35 35
     {
36 36
         if ($this->disable()) {
37 37
             return false;
38 38
         }
39
-        $path=$this->getPath($name);
40
-        $this->value[$name]=$value;
39
+        $path = $this->getPath($name);
40
+        $this->value[$name] = $value;
41 41
         FileSystem::makes(dirname($path));
42
-        $value=serialize($value);
42
+        $value = serialize($value);
43 43
         if (is_null($expire)) {
44
-            $expire=time() + $this->defaultLiveTime;
44
+            $expire = time() + $this->defaultLiveTime;
45 45
         }
46
-        return file_put_contents($path, $expire.'|'.$value)!==false;
46
+        return file_put_contents($path, $expire.'|'.$value) !== false;
47 47
     }
48 48
 
49 49
     /**
@@ -51,19 +51,19 @@  discard block
 block discarded – undo
51 51
      * @param string $name 名
52 52
      * @return mixed|null
53 53
      */
54
-    public function get(string $name, $defalut=null)
54
+    public function get(string $name, $defalut = null)
55 55
     {
56 56
         // 有值就获取值
57 57
         if (array_key_exists($name, $this->value)) {
58
-            $value=$this->value[$name];
58
+            $value = $this->value[$name];
59 59
             return $value;
60 60
         }
61 61
         // 没值就在cache文件中查找
62
-        $path=$this->getPath($name);
62
+        $path = $this->getPath($name);
63 63
         if (FileSystem::exist($path)) {
64
-            $value=FileSystem::get($path);
65
-            list($time, $value)=explode('|', $value, 2);
66
-            if (time()<intval($time)) {
64
+            $value = FileSystem::get($path);
65
+            list($time, $value) = explode('|', $value, 2);
66
+            if (time() < intval($time)) {
67 67
                 // 未过期则返回
68 68
                 return unserialize($value);
69 69
             } else {
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
      */
95 95
     public function has(string $name):bool
96 96
     {
97
-        return $this->get($name)!==null;
97
+        return $this->get($name) !== null;
98 98
     }
99 99
 
100 100
     /**
@@ -102,11 +102,11 @@  discard block
 block discarded – undo
102 102
      */
103 103
     public function gc()
104 104
     {
105
-        $files=FileSystem::readFiles($this->path, true);
105
+        $files = FileSystem::readFiles($this->path, true);
106 106
         foreach ($files as $file) {
107
-            $value=FileSystem::get($file);
108
-            list($time, $value)=explode('|', $value, 2);
109
-            if (time()>intval($time)) {
107
+            $value = FileSystem::get($file);
108
+            list($time, $value) = explode('|', $value, 2);
109
+            if (time() > intval($time)) {
110 110
                 FileSystem::delete($file);
111 111
             }
112 112
         }
@@ -130,12 +130,12 @@  discard block
 block discarded – undo
130 130
     private function getPath(string $name)
131 131
     {
132 132
         if (strpos($name, '.')) {
133
-            list($main, $sub)=explode('.', $name, 2);
133
+            list($main, $sub) = explode('.', $name, 2);
134 134
         } else {
135
-            $main=$name;
136
-            $sub=$name;
135
+            $main = $name;
136
+            $sub = $name;
137 137
         }
138
-        $fname= $this->path.'/'.substr(md5($main), 0, 8).'-'.substr(md5($sub), 0, 4).'.cache';
138
+        $fname = $this->path.'/'.substr(md5($main), 0, 8).'-'.substr(md5($sub), 0, 4).'.cache';
139 139
         return $fname;
140 140
     }
141 141
 }
Please login to merge, or discard this patch.