Commit 2ed722da authored by Rolf Forst's avatar Rolf Forst
Browse files

Refactoring

parent 4d1de030
......@@ -30,7 +30,7 @@ final class File
public static function storeItem($data = '')
{
if (empty($data)) {
do_action('rrze.log.error', __('{plugin}: Can not save cache item. The data is empty.', 'rrze-cache'), ['plugin' =>'rrze-cache', 'method' => __METHOD__]);
do_action('rrze.log.error', __('{plugin}: Can not save cache item. The data is empty.', 'rrze-cache'), ['plugin' => 'rrze-cache', 'method' => __METHOD__]);
return false;
}
......@@ -60,15 +60,15 @@ final class File
*/
public static function deleteItem($url = '')
{
if (! filter_var($url, FILTER_VALIDATE_URL)) {
do_action('rrze.log.error', __('{pluginn}: The URL is not valid.'), ['plugin' =>'rrze-cache', 'method' => __METHOD__]);
if (!filter_var($url, FILTER_VALIDATE_URL)) {
do_action('rrze.log.error', __('{pluginn}: The URL is not valid.'), ['plugin' => 'rrze-cache', 'method' => __METHOD__]);
return false;
}
$url_path = parse_url(($url ? $url : $_SERVER['REQUEST_URI']), PHP_URL_PATH);
$recursive = untrailingslashit($url_path) ? true : false;
self::clearDir(self::filePath($url), $recursive);
self::removeDir(self::filePath($url), $recursive);
}
/**
......@@ -78,9 +78,9 @@ final class File
public static function clearData($clearAll = false)
{
if ($clearAll === false) {
self::clearDir(self::dirPath());
self::removeDir(self::dirPath());
} else {
self::clearDir(self::$cacheDir);
self::removeDir(self::$cacheDir);
}
}
......@@ -101,8 +101,8 @@ final class File
protected static function createFiles($data)
{
$filePath = self::filePath();
if (! wp_mkdir_p($filePath)) {
do_action('rrze.log.error', __('{plugin}: The directory could not be created.', 'rrze-cache'), ['plugin' =>'rrze-cache', 'method' => __METHOD__, '$filePath' => $filePath]);
if (!wp_mkdir_p($filePath)) {
do_action('rrze.log.error', __('{plugin}: The directory could not be created.', 'rrze-cache'), ['plugin' => 'rrze-cache', 'method' => __METHOD__, '$filePath' => $filePath]);
return false;
}
......@@ -117,8 +117,8 @@ final class File
*/
protected static function createTimeoutFile($cacheExpires)
{
if (! wp_mkdir_p(self::$cacheDir)) {
do_action('rrze.log.error', __('{plugin}: The directory could not be created.', 'rrze-cache'), ['plugin' =>'rrze-cache', 'method' => __METHOD__, 'File::$cacheDir' => self::$cacheDir]);
if (!wp_mkdir_p(self::$cacheDir)) {
do_action('rrze.log.error', __('{plugin}: The directory could not be created.', 'rrze-cache'), ['plugin' => 'rrze-cache', 'method' => __METHOD__, 'File::$cacheDir' => self::$cacheDir]);
return false;
}
......@@ -129,8 +129,8 @@ final class File
'timeout'
);
if (! $handle = @fopen($file, 'wb')) {
do_action('rrze.log.error', __('{plugin}: The timeout cache file could not be written.', 'rrze-cache'), ['plugin' =>'rrze-cache', 'method' => __METHOD__, '$file' => $file]);
if (!$handle = @fopen($file, 'wb')) {
do_action('rrze.log.error', __('{plugin}: The timeout cache file could not be written.', 'rrze-cache'), ['plugin' => 'rrze-cache', 'method' => __METHOD__, '$file' => $file]);
return false;
}
......@@ -151,8 +151,8 @@ final class File
*/
protected static function writeFile($file, $data)
{
if (! $handle = @fopen($file, 'wb')) {
do_action('rrze.log.error', __('{plugin}: The cache file could not be written.', 'rrze-cache'), ['plugin' =>'rrze-cache', 'method' => __METHOD__, '$file' => $file]);
if (!$handle = @fopen($file, 'wb')) {
do_action('rrze.log.error', __('{plugin}: The cache file could not be written.', 'rrze-cache'), ['plugin' => 'rrze-cache', 'method' => __METHOD__, '$file' => $file]);
return false;
}
......@@ -179,16 +179,16 @@ final class File
}
/**
* [clearDir description]
* [removeDir description]
* @param string $dir [description]
* @param boolean $recursive [description]
* @return void
*/
protected static function clearDir($dir, $recursive = true)
protected static function removeDir($dir, $recursive = true)
{
$dir = untrailingslashit($dir);
if (! is_dir($dir)) {
if (!is_dir($dir)) {
return;
}
......@@ -202,7 +202,7 @@ final class File
$filename = $dir . DIRECTORY_SEPARATOR . $filename;
if (is_dir($filename) && $recursive) {
self::clearDir($filename, $recursive);
self::removeDir($filename, $recursive);
} else {
unlink($filename);
}
......@@ -227,7 +227,7 @@ final class File
);
if (validate_file($path) > 0) {
do_action('rrze.log.error', __('{plugin}: Invalid file path.'), ['plugin' =>'rrze-cache', 'method' => __METHOD__, '$path' => $path]);
do_action('rrze.log.error', __('{plugin}: Invalid file path.'), ['plugin' => 'rrze-cache', 'method' => __METHOD__, '$path' => $path]);
return false;
}
......@@ -250,7 +250,7 @@ final class File
);
if (validate_file($path) > 0) {
do_action('rrze.log.error', __('{plugin}: Invalid file path.', 'rrze-cache'), ['plugin' =>'rrze-cache', 'method' => __METHOD__, '$path' => $path]);
do_action('rrze.log.error', __('{plugin}: Invalid file path.', 'rrze-cache'), ['plugin' => 'rrze-cache', 'method' => __METHOD__, '$path' => $path]);
return false;
}
......@@ -265,5 +265,4 @@ final class File
{
return self::filePath() . 'index.html';
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment