Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Commit

Permalink
run code inspection check
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Feb 27, 2019
1 parent e7df10c commit cf55fa8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
20 changes: 10 additions & 10 deletions src/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);

Expand All @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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.');
Expand All @@ -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) {
//检查目录是否存在,不存在就先创建(多级)目录
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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');
Expand Down
16 changes: 8 additions & 8 deletions src/FileFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public function getChildren()
}
}

public function rewind()
public function rewind(): void
{
if (false === $this->isRewindable()) {
return;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand All @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand Down
8 changes: 4 additions & 4 deletions src/ModifyWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -275,23 +275,23 @@ private function collectDirMd5(string $watchDir)
/**
* @return string|null
*/
public function getIdFile()
public function getIdFile(): ?string
{
return $this->idFile;
}

/**
* @return string|null
*/
public function getWatchDir()
public function getWatchDir(): ?string
{
return $this->watchDirs;
}

/**
* @return string|null
*/
public function getDirMd5()
public function getDirMd5(): ?string
{
return $this->dirMd5;
}
Expand Down

0 comments on commit cf55fa8

Please sign in to comment.