core/Group/Cache/LocalFileCacheService.php
<?php namespace Group\Cache; class LocalFileCacheService{ protected static $cacheDir = "runtime/cache"; /** * 获取cache * * @param cacheName, name::key * @param cacheDir * @return string|array */The method get has a boolean flag argument $cacheDir, which is a certain sign of a Single Responsibility Principle violation. public function get($cacheName, $cacheDir = false) { $cacheDir = $cacheDir == false ? self::$cacheDir : $cacheDir; if (defined('__FILEROOT__')) { $dir = __FILEROOT__;The method get uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. } else { $dir = __ROOT__; } $dir = $dir.$cacheDir."/".$cacheName; Inline control structures are not allowed if ($this->isExist($cacheName, $cacheDir)) return require_once $dir; return null; } /** * 设置cache * * @param cacheName(string) * @param data(array) * @param cacheDir(string) */Function `set` has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
The method set has a boolean flag argument $cacheDir, which is a certain sign of a Single Responsibility Principle violation.
The method set has a boolean flag argument $flag, which is a certain sign of a Single Responsibility Principle violation. public function set($cacheName, $data, $cacheDir = false, $flag = false) { $cacheDir = $cacheDir == false ? self::$cacheDir : $cacheDir; if (defined('__FILEROOT__')) { $dir = __FILEROOT__;The method set uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. } else { $dir = __ROOT__; } $dir = $dir.$cacheDir."/".$cacheName; if (is_array($data)) { $data = var_export($data, true); $data = "<?phpreturn ".$data.";"; } $parts = explode('/', $dir); $file = array_pop($parts); $dir = ''; foreach ($parts as $part) { if (!is_dir($dir .= "$part/")) { mkdir($dir); } } file_put_contents("$dir/$file", $data, $flag); } /** * 文件是否存在 * * @param cacheName(string) * @param cacheDir(string) * @return boolean */The method isExist has a boolean flag argument $cacheDir, which is a certain sign of a Single Responsibility Principle violation. public function isExist($cacheName, $cacheDir = false) { $cacheDir = $cacheDir == false ? self::$cacheDir : $cacheDir; if (defined('__FILEROOT__')) { $dir = __FILEROOT__;The method isExist uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. } else { $dir = __ROOT__; } $dir = $dir.$cacheDir."/".$cacheName; return file_exists($dir); Function closing brace must go on the next line following the body; found 1 blank lines before brace } Remove error control operator '@' on line 95.
The method remove has a boolean flag argument $cacheDir, which is a certain sign of a Single Responsibility Principle violation.
Avoid unused parameters such as '$filename'. public function remove($filename, $cacheDir = false) { $cacheDir = $cacheDir == false ? self::$cacheDir : $cacheDir; if (defined('__FILEROOT__')) { $dir = __FILEROOT__;The method remove uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. } else { $dir = __ROOT__; }Avoid using undefined variables such as '$cacheName' which will lead to PHP notices.
Avoid unused local variables such as '$cacheName'. $dir = $dir.$cacheDir."/".$cacheName; return @unlink($dir); }}