diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php index fbe86c195..f80705a42 100644 --- a/System/File/Local/Directory.php +++ b/System/File/Local/Directory.php @@ -79,6 +79,10 @@ class Directory extends FileAbstract implements DirectoryInterface */ public static function list(string $path, string $filter = '*') : array { + if (!file_exists($path)) { + throw new PathException($path); + } + $list = []; $path = rtrim($path, '\\/'); @@ -152,6 +156,10 @@ class Directory extends FileAbstract implements DirectoryInterface */ public static function size(string $dir, bool $recursive = true) : int { + if (!file_exists($dir)) { + throw new PathException($dir); + } + $countSize = 0; $count = 0; @@ -180,6 +188,10 @@ class Directory extends FileAbstract implements DirectoryInterface */ public static function count(string $path, bool $recursive = true, array $ignore = []) : int { + if (!file_exists($path)) { + throw new PathException($path); + } + $size = 0; $files = scandir($path); $ignore[] = '.'; @@ -206,10 +218,6 @@ class Directory extends FileAbstract implements DirectoryInterface */ public static function delete(string $path) : bool { - if (!file_exists($path) || !is_dir($path)) { - throw new PathException($path); - } - $files = scandir($path); /* Removing . and .. */ @@ -247,10 +255,7 @@ class Directory extends FileAbstract implements DirectoryInterface public static function created(string $path) : \DateTime { if(!file_exists($path)) { - $created = new \DateTime(); - $created->setTimestamp(0); - - return $created; + throw new PathException($path); } $created = new \DateTime('now'); @@ -303,6 +308,10 @@ class Directory extends FileAbstract implements DirectoryInterface */ public static function copy(string $from, string $to, bool $overwrite = false) : bool { + if (!is_dir($from)) { + throw new PathException($from); + } + if(!$overwrite && file_exists($to)) { return false; } @@ -330,6 +339,10 @@ class Directory extends FileAbstract implements DirectoryInterface */ public static function move(string $from, string $to, bool $overwrite = false) : bool { + if (!is_dir($from)) { + throw new PathException($from); + } + if (!$overwrite && file_exists($to)) { return false; } diff --git a/System/File/Local/File.php b/System/File/Local/File.php index 6d966b222..1e9107d4e 100644 --- a/System/File/Local/File.php +++ b/System/File/Local/File.php @@ -259,7 +259,7 @@ class File extends FileAbstract implements FileInterface */ public static function copy(string $from, string $to, bool $overwrite = false) : bool { - if (!file_exists($from)) { + if (!is_file($from)) { throw new PathException($from); } @@ -281,7 +281,7 @@ class File extends FileAbstract implements FileInterface */ public static function move(string $from, string $to, bool $overwrite = false) : bool { - if (!file_exists($from)) { + if (!is_file($from)) { throw new PathException($from); }