Completed
Pull Request — 2.2 (#6)
by Kevin
02:06
created
src/BigFileCache.php 5 patches
Doc Comments   +6 added lines, -1 removed lines patch added patch discarded remove patch
@@ -69,7 +69,6 @@  discard block
 block discarded – undo
69 69
      * @param LoggerInterface|LogInterface $log
70 70
      * @param string $cacheDirectory
71 71
      * @param boolean $relativeToSystemTempDirectory
72
-     * @param int $hashDepth
73 72
      */
74 73
     function __construct($defaultTimeToLive, $log, $cacheDirectory, $relativeToSystemTempDirectory)
75 74
     {
@@ -263,6 +262,9 @@  discard block
 block discarded – undo
263 262
 		return $dir.$subFolder;
264 263
 	}
265 264
 
265
+	/**
266
+	 * @param string $key
267
+	 */
266 268
 	protected function getFileName($key) {
267 269
         $subFolder = $this->getDirectory($key);
268 270
 		// Remove any "/" and ":" from the name, and replace those with "_" ...
@@ -281,6 +283,9 @@  discard block
 block discarded – undo
281 283
 		return $subFolder.md5($key).'.cache';
282 284
 	}
283 285
 
286
+    /**
287
+     * @param string $dir
288
+     */
284 289
     private static function rrmdir($dir) {
285 290
         if (is_dir($dir)) {
286 291
             $objects = scandir($dir);
Please login to merge, or discard this patch.
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Mouf\Utils\Cache;
3 3
 
4
-use Mouf\Utils\Log\LogInterface;
4
+use Mouf\Utils\Log\LogInterface;
5 5
 use Psr\Log\LoggerInterface;
6 6
 
7 7
 /**
Please login to merge, or discard this patch.
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 * @Property
35 35
 	 * @var int
36 36
 	 */
37
-    private $defaultTimeToLive;
37
+	private $defaultTimeToLive;
38 38
 	
39 39
 	/**
40 40
 	 * The logger used to trace the cache activity.
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @var LoggerInterface|LogInterface
44 44
 	 */
45
-    private $log;
45
+	private $log;
46 46
 
47 47
 	/**
48 48
 	 * The directory the files are stored in.
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 * @Property
53 53
 	 * @var string
54 54
 	 */
55
-    private $cacheDirectory;
55
+	private $cacheDirectory;
56 56
 		
57 57
 	/**
58 58
 	 * Whether the directory is relative to the system temp directory or not.
@@ -60,49 +60,49 @@  discard block
 block discarded – undo
60 60
 	 * @Property
61 61
 	 * @var boolean
62 62
 	 */
63
-    private $relativeToSystemTempDirectory = true;
63
+	private $relativeToSystemTempDirectory = true;
64 64
 
65
-    private $hashDepth = 2;
65
+	private $hashDepth = 2;
66 66
 
67
-    /**
68
-     * @param int $defaultTimeToLive
69
-     * @param LoggerInterface|LogInterface $log
70
-     * @param string $cacheDirectory
71
-     * @param boolean $relativeToSystemTempDirectory
72
-     * @param int $hashDepth
73
-     */
74
-    function __construct($defaultTimeToLive, $log, $cacheDirectory, $relativeToSystemTempDirectory)
75
-    {
76
-        $this->defaultTimeToLive = $defaultTimeToLive;
77
-        $this->log = $log;
78
-        $this->cacheDirectory = $cacheDirectory;
79
-        $this->relativeToSystemTempDirectory = $relativeToSystemTempDirectory;
80
-    }
67
+	/**
68
+	 * @param int $defaultTimeToLive
69
+	 * @param LoggerInterface|LogInterface $log
70
+	 * @param string $cacheDirectory
71
+	 * @param boolean $relativeToSystemTempDirectory
72
+	 * @param int $hashDepth
73
+	 */
74
+	function __construct($defaultTimeToLive, $log, $cacheDirectory, $relativeToSystemTempDirectory)
75
+	{
76
+		$this->defaultTimeToLive = $defaultTimeToLive;
77
+		$this->log = $log;
78
+		$this->cacheDirectory = $cacheDirectory;
79
+		$this->relativeToSystemTempDirectory = $relativeToSystemTempDirectory;
80
+	}
81 81
 
82
-    /**
83
-     * Must be between 1 and 4
84
-     * Sets the length of the subdirectory. The higher it is, the more subfolders will be created, but the lesser cache file they will contain.
85
-     * Max count of subfolders is 16^$hashDepth, so you cannot set a depth higher then 4 as it could create more than 1 000 000 subfolders
86
-     * As an example :
87
-     *    - 1 000 000 items are stored into 256 subfolders for $hashDepth == 2, witch means around 4 000 files per folder
88
-     *    - 1 000 000 items are stored into 4096 subfolders for $hashDepth == 3, witch means around 250 files per folder
89
-     *
90
-     * If you consider caching more than 1 000 000 items, you should consider another cache service
91
-     *
92
-     * @param int $hashDepth
93
-     */
94
-    public function setHashDepth($hashDepth)
95
-    {
96
-        if ($hashDepth > 4 || $hashDepth < 1){
97
-            throw new \Exception("hashDepth property should be betwwen 1 and 4");
98
-        }
99
-        $this->hashDepth = $hashDepth;
100
-    }
82
+	/**
83
+	 * Must be between 1 and 4
84
+	 * Sets the length of the subdirectory. The higher it is, the more subfolders will be created, but the lesser cache file they will contain.
85
+	 * Max count of subfolders is 16^$hashDepth, so you cannot set a depth higher then 4 as it could create more than 1 000 000 subfolders
86
+	 * As an example :
87
+	 *    - 1 000 000 items are stored into 256 subfolders for $hashDepth == 2, witch means around 4 000 files per folder
88
+	 *    - 1 000 000 items are stored into 4096 subfolders for $hashDepth == 3, witch means around 250 files per folder
89
+	 *
90
+	 * If you consider caching more than 1 000 000 items, you should consider another cache service
91
+	 *
92
+	 * @param int $hashDepth
93
+	 */
94
+	public function setHashDepth($hashDepth)
95
+	{
96
+		if ($hashDepth > 4 || $hashDepth < 1){
97
+			throw new \Exception("hashDepth property should be betwwen 1 and 4");
98
+		}
99
+		$this->hashDepth = $hashDepth;
100
+	}
101 101
 
102 102
 
103 103
 
104 104
 
105
-    /**
105
+	/**
106 106
 	 * Returns the cached value for the key passed in parameter.
107 107
 	 *
108 108
 	 * @param string $key
@@ -112,11 +112,11 @@  discard block
 block discarded – undo
112 112
 		$filename = $this->getFileName($key);
113 113
 
114 114
 		if (is_readable($filename)) {
115
-            $fp = fopen($filename, "r");
116
-            if ($fp === false) {//File may have been deleted between is_readable and fopen
117
-                return null;
118
-            }
119
-            $timeout = fgets($fp);
115
+			$fp = fopen($filename, "r");
116
+			if ($fp === false) {//File may have been deleted between is_readable and fopen
117
+				return null;
118
+			}
119
+			$timeout = fgets($fp);
120 120
 			
121 121
 			if ($timeout > time() || $timeout==0) {
122 122
 				$contents = "";
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 			}
177 177
 		}
178 178
 
179
-        $oldUmask = umask(0);
179
+		$oldUmask = umask(0);
180 180
 		$subfolder = $this->getDirectory($key);
181 181
 		if (!is_writable($filename)) {
182 182
 			if (!file_exists($subfolder)) {
@@ -198,10 +198,10 @@  discard block
 block discarded – undo
198 198
 		fwrite($fp, $timeOut."\n");
199 199
 		fwrite($fp, serialize($value));
200 200
 		fclose($fp);
201
-        // Cache is shared with group, not with the rest of the world.
202
-        chmod($filename, 0660);
201
+		// Cache is shared with group, not with the rest of the world.
202
+		chmod($filename, 0660);
203 203
 
204
-        umask($oldUmask);
204
+		umask($oldUmask);
205 205
 	}
206 206
 	
207 207
 	/**
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
 				$this->log->trace("Purging the whole file cache.");
236 236
 			}
237 237
 		}
238
-        self::rrmdir($this->getDirectory());
238
+		self::rrmdir($this->getDirectory());
239 239
 	}
240 240
 
241
-    /**
242
-     * @param mixed $key : if set, this function will return the cache directory WITH subfolder
243
-     * @return string
244
-     */
241
+	/**
242
+	 * @param mixed $key : if set, this function will return the cache directory WITH subfolder
243
+	 * @return string
244
+	 */
245 245
 	protected function getDirectory($key = null) {
246 246
 
247 247
 		$dir = "";
@@ -254,26 +254,26 @@  discard block
 block discarded – undo
254 254
 			$dir .= "filecache/";
255 255
 		}
256 256
 
257
-        if ($key){
258
-            $subFolder = substr(hash("sha256", $key), 0, $this->hashDepth) . "/";
259
-        }else{
260
-            $subFolder = "";
261
-        }
257
+		if ($key){
258
+			$subFolder = substr(hash("sha256", $key), 0, $this->hashDepth) . "/";
259
+		}else{
260
+			$subFolder = "";
261
+		}
262 262
 
263 263
 		return $dir.$subFolder;
264 264
 	}
265 265
 
266 266
 	protected function getFileName($key) {
267
-        $subFolder = $this->getDirectory($key);
267
+		$subFolder = $this->getDirectory($key);
268 268
 		// Remove any "/" and ":" from the name, and replace those with "_" ...
269 269
 		$key = str_replace(array("_", "/", "\\", ":"), array("___", "_s_", "_b_", "_d_"), $key);
270 270
 
271
-        // Windows full path need to be less than 260 characters. We need to limit the size of the filename
272
-        $fullPath = $subFolder.$key.".cache";
271
+		// Windows full path need to be less than 260 characters. We need to limit the size of the filename
272
+		$fullPath = $subFolder.$key.".cache";
273 273
 
274
-        // Approximative value due to NTFS short file names (e.g. PROGRA~1) that get longer when evaluated by Windows
275
-        if (strlen($fullPath)<160) {
276
-            return $fullPath;
274
+		// Approximative value due to NTFS short file names (e.g. PROGRA~1) that get longer when evaluated by Windows
275
+		if (strlen($fullPath)<160) {
276
+			return $fullPath;
277 277
 		}
278 278
 		
279 279
 
@@ -281,18 +281,18 @@  discard block
 block discarded – undo
281 281
 		return $subFolder.md5($key).'.cache';
282 282
 	}
283 283
 
284
-    private static function rrmdir($dir) {
285
-        if (is_dir($dir)) {
286
-            $objects = scandir($dir);
287
-            foreach ($objects as $object) {
288
-                if ($object != "." && $object != "..") {
289
-                    if (filetype($dir."/".$object) == "dir")
290
-                        self::rrmdir($dir."/".$object);
291
-                    else unlink   ($dir."/".$object);
292
-                }
293
-            }
294
-            reset($objects);
295
-            rmdir($dir);
296
-        }
297
-    }
284
+	private static function rrmdir($dir) {
285
+		if (is_dir($dir)) {
286
+			$objects = scandir($dir);
287
+			foreach ($objects as $object) {
288
+				if ($object != "." && $object != "..") {
289
+					if (filetype($dir."/".$object) == "dir")
290
+						self::rrmdir($dir."/".$object);
291
+					else unlink   ($dir."/".$object);
292
+				}
293
+			}
294
+			reset($objects);
295
+			rmdir($dir);
296
+		}
297
+	}
298 298
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      */
94 94
     public function setHashDepth($hashDepth)
95 95
     {
96
-        if ($hashDepth > 4 || $hashDepth < 1){
96
+        if ($hashDepth > 4 || $hashDepth < 1) {
97 97
             throw new \Exception("hashDepth property should be betwwen 1 and 4");
98 98
         }
99 99
         $this->hashDepth = $hashDepth;
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
             }
119 119
             $timeout = fgets($fp);
120 120
 			
121
-			if ($timeout > time() || $timeout==0) {
121
+			if ($timeout > time() || $timeout == 0) {
122 122
 				$contents = "";
123 123
 				while (!feof($fp)) {
124 124
 				  $contents .= fread($fp, 65536);
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
 			$dir .= "filecache/";
255 255
 		}
256 256
 
257
-        if ($key){
258
-            $subFolder = substr(hash("sha256", $key), 0, $this->hashDepth) . "/";
259
-        }else{
257
+        if ($key) {
258
+            $subFolder = substr(hash("sha256", $key), 0, $this->hashDepth)."/";
259
+        } else {
260 260
             $subFolder = "";
261 261
         }
262 262
 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
         $fullPath = $subFolder.$key.".cache";
273 273
 
274 274
         // Approximative value due to NTFS short file names (e.g. PROGRA~1) that get longer when evaluated by Windows
275
-        if (strlen($fullPath)<160) {
275
+        if (strlen($fullPath) < 160) {
276 276
             return $fullPath;
277 277
 		}
278 278
 		
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 if ($object != "." && $object != "..") {
289 289
                     if (filetype($dir."/".$object) == "dir")
290 290
                         self::rrmdir($dir."/".$object);
291
-                    else unlink   ($dir."/".$object);
291
+                    else unlink($dir."/".$object);
292 292
                 }
293 293
             }
294 294
             reset($objects);
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 
257 257
         if ($key){
258 258
             $subFolder = substr(hash("sha256", $key), 0, $this->hashDepth) . "/";
259
-        }else{
259
+        } else{
260 260
             $subFolder = "";
261 261
         }
262 262
 
@@ -286,9 +286,11 @@  discard block
 block discarded – undo
286 286
             $objects = scandir($dir);
287 287
             foreach ($objects as $object) {
288 288
                 if ($object != "." && $object != "..") {
289
-                    if (filetype($dir."/".$object) == "dir")
290
-                        self::rrmdir($dir."/".$object);
291
-                    else unlink   ($dir."/".$object);
289
+                    if (filetype($dir."/".$object) == "dir") {
290
+                                            self::rrmdir($dir."/".$object);
291
+                    } else {
292
+                    	unlink   ($dir."/".$object);
293
+                    }
292 294
                 }
293 295
             }
294 296
             reset($objects);
Please login to merge, or discard this patch.
src/FileCacheInstaller.php 2 patches
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Mouf\Utils\Cache;
3 3
 
4
-use Mouf\Installer\PackageInstallerInterface;
4
+use Mouf\Installer\PackageInstallerInterface;
5 5
 use Mouf\MoufManager;
6 6
 
7 7
 /**
Please login to merge, or discard this patch.
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -9,30 +9,30 @@
 block discarded – undo
9 9
  */
10 10
 class FileCacheInstaller implements PackageInstallerInterface {
11 11
 
12
-    /**
13
-     * (non-PHPdoc)
14
-     * @see \Mouf\Installer\PackageInstallerInterface::install()
15
-     */
16
-    public static function install(MoufManager $moufManager) {
17
-        if (!$moufManager->instanceExists("fileCacheService")) {
18
-            $fileCacheService = $moufManager->createInstance("Mouf\\Utils\\Cache\\FileCache");
19
-            $fileCacheService->setName("fileCacheService");
20
-            $fileCacheService->getProperty("defaultTimeToLive")->setValue(3600);
21
-            /*if ($moufManager->instanceExists("psr.errorLogLogger")) {
12
+	/**
13
+	 * (non-PHPdoc)
14
+	 * @see \Mouf\Installer\PackageInstallerInterface::install()
15
+	 */
16
+	public static function install(MoufManager $moufManager) {
17
+		if (!$moufManager->instanceExists("fileCacheService")) {
18
+			$fileCacheService = $moufManager->createInstance("Mouf\\Utils\\Cache\\FileCache");
19
+			$fileCacheService->setName("fileCacheService");
20
+			$fileCacheService->getProperty("defaultTimeToLive")->setValue(3600);
21
+			/*if ($moufManager->instanceExists("psr.errorLogLogger")) {
22 22
                 $fileCacheService->getProperty("log")->setValue($moufManager->getInstanceDescriptor("psr.errorLogLogger"));
23 23
             }*/
24
-        } else {
25
-            $fileCacheService = $moufManager->getInstanceDescriptor("fileCacheService");
26
-        }
24
+		} else {
25
+			$fileCacheService = $moufManager->getInstanceDescriptor("fileCacheService");
26
+		}
27 27
 
28
-        $configManager = $moufManager->getConfigManager();
29
-        $constants = $configManager->getMergedConstants();
30
-        if (isset($constants['SECRET'])) {
31
-            $fileCacheService->getProperty('prefix')->setValue('SECRET')->setOrigin('config');
32
-        }
28
+		$configManager = $moufManager->getConfigManager();
29
+		$constants = $configManager->getMergedConstants();
30
+		if (isset($constants['SECRET'])) {
31
+			$fileCacheService->getProperty('prefix')->setValue('SECRET')->setOrigin('config');
32
+		}
33 33
 
34
-        // Let's rewrite the MoufComponents.php file to save the component
35
-        $moufManager->rewriteMouf();
36
-    }
34
+		// Let's rewrite the MoufComponents.php file to save the component
35
+		$moufManager->rewriteMouf();
36
+	}
37 37
 }
38 38
 ?>
39 39
\ No newline at end of file
Please login to merge, or discard this patch.
src/FileCache.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
 		$filename = $this->getFileName($key);
67 67
 
68 68
 		if (is_readable($filename)) {
69
-            $fp = fopen($filename, "r");
70
-            if ($fp === false) {//File may have been deleted between is_readable and fopen
71
-                return null;
72
-            }
73
-            $timeout = fgets($fp);
69
+			$fp = fopen($filename, "r");
70
+			if ($fp === false) {//File may have been deleted between is_readable and fopen
71
+				return null;
72
+			}
73
+			$timeout = fgets($fp);
74 74
 			
75 75
 			if ($timeout > time() || $timeout==0) {
76 76
 				$contents = "";
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 			}
131 131
 		}
132 132
 
133
-        $oldUmask = umask(0);
133
+		$oldUmask = umask(0);
134 134
 		
135 135
 		if (!is_writable($filename)) {
136 136
 			if (!file_exists($this->getDirectory())) {
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
 		fwrite($fp, $timeOut."\n");
153 153
 		fwrite($fp, serialize($value));
154 154
 		fclose($fp);
155
-        // Cache is shared with group, not with the rest of the world.
156
-        chmod($filename, 0660);
155
+		// Cache is shared with group, not with the rest of the world.
156
+		chmod($filename, 0660);
157 157
 
158
-        umask($oldUmask);
158
+		umask($oldUmask);
159 159
 	}
160 160
 	
161 161
 	/**
@@ -190,10 +190,10 @@  discard block
 block discarded – undo
190 190
 			}
191 191
 		}
192 192
 		$files = glob($this->getDirectory()."*");
193
-        $prefixFile = str_replace(array("_", "/", "\\", ":"), array("___", "_s_", "_b_", "_d_"), $this->prefix);
193
+		$prefixFile = str_replace(array("_", "/", "\\", ":"), array("___", "_s_", "_b_", "_d_"), $this->prefix);
194 194
 		foreach ($files as $filename) {
195 195
 			if (empty($prefixFile) || strpos(basename($filename), $prefixFile) === 0) {
196
-		    	unlink($filename);
196
+				unlink($filename);
197 197
 			}
198 198
 		}
199 199
 	}
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
             }
73 73
             $timeout = fgets($fp);
74 74
 			
75
-			if ($timeout > time() || $timeout==0) {
75
+			if ($timeout > time() || $timeout == 0) {
76 76
 				$contents = "";
77 77
 				while (!feof($fp)) {
78 78
 				  $contents .= fread($fp, 65536);
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 		$fullPath = $this->getDirectory().$key.".cache";
221 221
 		
222 222
 		// Approximative value due to NTFS short file names (e.g. PROGRA~1) that get longer when evaluated by Windows
223
-		if (strlen($fullPath)<160) {
223
+		if (strlen($fullPath) < 160) {
224 224
 			return $fullPath;
225 225
 		}
226 226
 		
Please login to merge, or discard this patch.
src/PhpFileCache.php 3 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 			}
84 84
 		}
85 85
 
86
-        $oldUmask = umask(0);
86
+		$oldUmask = umask(0);
87 87
 
88 88
 		if (!is_writable($filename)) {
89 89
 			if (!file_exists($this->getDirectory())) {
@@ -106,20 +106,20 @@  discard block
 block discarded – undo
106 106
 			'data'      => $value
107 107
 		);
108 108
 
109
-        $serializeData = serialize($data);
110
-        if(strpos($serializeData, 'r:') !== false || (is_object($value) && !method_exists($value, '__set_state'))){
111
-            $code   = sprintf('<?php return unserialize(%s);', var_export($serializeData, true));
112
-            file_put_contents($filename, $code);
113
-        }else{
114
-            $data  = var_export($data, true);
115
-            $code   = sprintf('<?php return %s;', $data);
116
-            file_put_contents($filename, $code);
117
-        }
109
+		$serializeData = serialize($data);
110
+		if(strpos($serializeData, 'r:') !== false || (is_object($value) && !method_exists($value, '__set_state'))){
111
+			$code   = sprintf('<?php return unserialize(%s);', var_export($serializeData, true));
112
+			file_put_contents($filename, $code);
113
+		}else{
114
+			$data  = var_export($data, true);
115
+			$code   = sprintf('<?php return %s;', $data);
116
+			file_put_contents($filename, $code);
117
+		}
118 118
 
119
-        // Cache is shared with group, not with the rest of the world.
120
-        chmod($filename, 0660);
119
+		// Cache is shared with group, not with the rest of the world.
120
+		chmod($filename, 0660);
121 121
 
122
-        umask($oldUmask);
122
+		umask($oldUmask);
123 123
 	}
124 124
 
125 125
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	public function get($key) {
32 32
 		$filename = $this->getFileName($key);
33 33
 
34
-		if ( ! is_file($filename)) {
34
+		if (!is_file($filename)) {
35 35
 			if ($this->log) {
36 36
 				if ($this->log instanceof LoggerInterface) {
37 37
 					$this->log->info("Retrieving key '{key}' from file cache: cache miss.", array('key'=>$key));
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
 		);
108 108
 
109 109
         $serializeData = serialize($data);
110
-        if(strpos($serializeData, 'r:') !== false || (is_object($value) && !method_exists($value, '__set_state'))){
111
-            $code   = sprintf('<?php return unserialize(%s);', var_export($serializeData, true));
110
+        if (strpos($serializeData, 'r:') !== false || (is_object($value) && !method_exists($value, '__set_state'))) {
111
+            $code = sprintf('<?php return unserialize(%s);', var_export($serializeData, true));
112 112
             file_put_contents($filename, $code);
113
-        }else{
114
-            $data  = var_export($data, true);
115
-            $code   = sprintf('<?php return %s;', $data);
113
+        } else {
114
+            $data = var_export($data, true);
115
+            $code = sprintf('<?php return %s;', $data);
116 116
             file_put_contents($filename, $code);
117 117
         }
118 118
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@
 block discarded – undo
110 110
         if(strpos($serializeData, 'r:') !== false || (is_object($value) && !method_exists($value, '__set_state'))){
111 111
             $code   = sprintf('<?php return unserialize(%s);', var_export($serializeData, true));
112 112
             file_put_contents($filename, $code);
113
-        }else{
113
+        } else{
114 114
             $data  = var_export($data, true);
115 115
             $code   = sprintf('<?php return %s;', $data);
116 116
             file_put_contents($filename, $code);
Please login to merge, or discard this patch.