diff --git a/src/Directory.php b/src/Directory.php index 5660403..5d3ebe6 100644 --- a/src/Directory.php +++ b/src/Directory.php @@ -180,27 +180,27 @@ public static function getDirs($path, $loop = false, $parent = null, array $list * @return array * @throws FileNotFoundException */ - public static function simpleInfo($dir, $ext = null, $recursive = false): array + public static function simpleInfo(string $dir, $ext = null, $recursive = false): array { $list = []; $dir = self::pathFormat($dir); - $ext = \is_array($ext) ? implode('|', $ext) : trim($ext); + $ext = \is_array($ext) ? \implode('|', $ext) : \trim($ext); - if (!is_dir($dir)) { + if (!\is_dir($dir)) { throw new FileNotFoundException("directory not exists! DIR: $dir"); } // glob()寻找与模式匹配的文件路径 $file is pull path - foreach (glob($dir . '*') as $file) { + foreach (\glob($dir . '*') as $file) { // 匹配文件 如果没有传入$ext 则全部遍历,传入了则按传入的类型来查找 - if (is_file($file) && (!$ext || preg_match("/\.($ext)$/i", $file))) { + if (\is_file($file) && (!$ext || \preg_match("/\.($ext)$/i", $file))) { //basename — 返回路径中的 文件名部分 - $list[] = basename($file); + $list[] = \basename($file); // is directory } else { - $list[] = '/' . basename($file); + $list[] = '/' . \basename($file); if ($recursive) { $list = array_merge($list, self::simpleInfo($file, $ext, $recursive)); @@ -221,7 +221,7 @@ public static function simpleInfo($dir, $ext = null, $recursive = false): array * @return array * @throws FileNotFoundException */ - public static function getFiles($path, $ext = null, $recursive = false, $parent = null, array $list = []): array + public static function getFiles(string $path, $ext = null, $recursive = false, $parent = null, array $list = []): array { $path = self::pathFormat($path); @@ -230,13 +230,13 @@ public static function getFiles($path, $ext = null, $recursive = false, $parent } $len = \strlen($path); - $ext = \is_array($ext) ? implode('|', $ext) : trim($ext); + $ext = \is_array($ext) ? \implode('|', $ext) : \trim($ext); foreach (glob($path . '*') as $v) { $relatePath = substr($v, $len); // 匹配文件 如果没有传入$ext 则全部遍历,传入了则按传入的类型来查找 - if (is_file($v) && (!$ext || preg_match("/\.($ext)$/i", $v))) { + if (\is_file($v) && (!$ext || \preg_match("/\.($ext)$/i", $v))) { $list[] = $parent . $relatePath; } elseif ($recursive) { diff --git a/src/File.php b/src/File.php index 805e83e..d7e918c 100644 --- a/src/File.php +++ b/src/File.php @@ -124,7 +124,7 @@ public static function save(string $filename, string $data): bool * @param $path * @throws IOException */ - public static function write($content, $path) + public static function write($content, $path): void { $handler = static::openHandler($path); @@ -154,7 +154,7 @@ public static function openHandler(string $path) * @param string $path The path to the file (for exception printing only). * @throws IOException */ - public static function writeToFile($handler, string $content, string $path = '') + public static function writeToFile($handler, string $content, string $path = ''): void { if (($result = @fwrite($handler, $content)) === false || ($result < \strlen($content))) { throw new IOException('The file "' . $path . '" could not be written to. Check your disk space and file permissions.'); @@ -172,7 +172,7 @@ public static function writeToFile($handler, string $content, string $path = '') * 'case.html' => 'content' , * ); **/ - public static function createAndWrite(array $fileData = [], $append = false, $mode = 0664) + public static function createAndWrite(array $fileData = [], $append = false, $mode = 0664): void { foreach ($fileData as $file => $content) { //检查目录是否存在,不存在就先创建(多级)目录 @@ -262,7 +262,7 @@ public static function getContents( * @throws FileSystemException * @throws IOException */ - public static function move(string $file, string $target) + public static function move(string $file, string $target): void { Directory::mkdir(\dirname($target)); @@ -388,7 +388,7 @@ public static function stripPhpCode(string $source): string * @param string $file * @param string $as */ - public static function downBigFile($file, $as) + public static function downBigFile($file, $as): void { header('Expires: Mon, 1 Apr 1974 05:00:00 GMT'); header('Pragma: no-cache'); diff --git a/src/FileFinder.php b/src/FileFinder.php index 98e179d..88efc5a 100644 --- a/src/FileFinder.php +++ b/src/FileFinder.php @@ -485,7 +485,7 @@ public function getChildren() } } - public function rewind() + public function rewind(): void { if (false === $this->isRewindable()) { return; @@ -501,8 +501,8 @@ public function isRewindable() } if (false !== $stream = @opendir($this->getPath())) { - $infoS = stream_get_meta_data($stream); - closedir($stream); + $infoS = \stream_get_meta_data($stream); + \closedir($stream); if ($infoS['seekable']) { return $this->rewindable = true; @@ -522,7 +522,7 @@ public function isRewindable() public function __construct(\RecursiveIterator $iterator, array $excludes) { - $this->excludes = array_flip($excludes); + $this->excludes = \array_flip($excludes); $this->iterator = $iterator; parent::__construct($iterator); @@ -598,14 +598,14 @@ public function accept(): bool $pathname = $this->current()->getFilename(); foreach ($this->notNames as $not) { - if (fnmatch($not, $pathname)) { + if (\fnmatch($not, $pathname)) { return false; } } if ($this->names) { foreach ($this->names as $need) { - if (fnmatch($need, $pathname)) { + if (\fnmatch($need, $pathname)) { return true; } } @@ -665,14 +665,14 @@ public function accept(): bool } foreach ($this->notPaths as $not) { - if (fnmatch($not, $pathname)) { + if (\fnmatch($not, $pathname)) { return false; } } if ($this->paths) { foreach ($this->paths as $need) { - if (fnmatch($need, $pathname)) { + if (\fnmatch($need, $pathname)) { return true; } } diff --git a/src/FileSystem.php b/src/FileSystem.php index e6cd7c3..fcc6b10 100644 --- a/src/FileSystem.php +++ b/src/FileSystem.php @@ -116,7 +116,7 @@ public static function exists(string $file, $type = null) * @throws FileNotFoundException * @throws \InvalidArgumentException */ - public static function check(string $file, $ext = null) + public static function check(string $file, $ext = null): void { if (!$file || !file_exists($file)) { throw new FileNotFoundException("File {$file} not exists!"); @@ -142,7 +142,7 @@ public static function check(string $file, $ext = null) * @throws IOException When target file or directory already exists * @throws IOException When origin cannot be renamed */ - public static function rename(string $origin, string $target, bool $overwrite = false) + public static function rename(string $origin, string $target, bool $overwrite = false): void { // we check that target does not exist if (!$overwrite && static::isReadable($target)) { @@ -176,7 +176,7 @@ public static function isReadable(string $filename): bool * @param int $mode The directory mode * @throws IOException On any directory creation failure */ - public static function mkdir($dirs, $mode = 0777) + public static function mkdir($dirs, $mode = 0777): void { foreach (Arr::toIterator($dirs) as $dir) { if (is_dir($dir)) { @@ -207,7 +207,7 @@ public static function mkdir($dirs, $mode = 0777) * @param bool $recursive Whether change the mod recursively or not * @throws IOException When the change fail */ - public static function chmod($files, $mode, $umask = 0000, $recursive = false) + public static function chmod($files, $mode, $umask = 0000, $recursive = false): void { foreach (Arr::toIterator($files) as $file) { if (true !== @chmod($file, $mode & ~$umask)) { @@ -228,7 +228,7 @@ public static function chmod($files, $mode, $umask = 0000, $recursive = false) * @param bool $recursive Whether change the owner recursively or not * @throws IOException When the change fail */ - public static function chown($files, string $user, $recursive = false) + public static function chown($files, string $user, $recursive = false): void { foreach (Arr::toIterator($files) as $file) { if ($recursive && is_dir($file) && !is_link($file)) { diff --git a/src/ModifyWatcher.php b/src/ModifyWatcher.php index 3df58ba..4715666 100644 --- a/src/ModifyWatcher.php +++ b/src/ModifyWatcher.php @@ -225,7 +225,7 @@ public function calcMd5Hash(): string /** * @param string $watchDir */ - private function collectDirMd5(string $watchDir) + private function collectDirMd5(string $watchDir): void { $files = scandir($watchDir, 0); @@ -275,7 +275,7 @@ private function collectDirMd5(string $watchDir) /** * @return string|null */ - public function getIdFile() + public function getIdFile(): ?string { return $this->idFile; } @@ -283,7 +283,7 @@ public function getIdFile() /** * @return string|null */ - public function getWatchDir() + public function getWatchDir(): ?string { return $this->watchDirs; } @@ -291,7 +291,7 @@ public function getWatchDir() /** * @return string|null */ - public function getDirMd5() + public function getDirMd5(): ?string { return $this->dirMd5; }