diff --git a/src/File.php b/src/File.php index 780242c..805e83e 100644 --- a/src/File.php +++ b/src/File.php @@ -23,11 +23,11 @@ abstract class File extends FileSystem { use ReadTrait; - const FORMAT_JSON = 'json'; - const FORMAT_PHP = 'php'; - const FORMAT_INI = 'ini'; - const FORMAT_YML = 'yml'; - const FORMAT_YAML = 'yml'; + public const FORMAT_JSON = 'json'; + public const FORMAT_PHP = 'php'; + public const FORMAT_INI = 'ini'; + public const FORMAT_YML = 'yml'; + public const FORMAT_YAML = 'yml'; /** * 获得文件名称 diff --git a/src/FileFinder.php b/src/FileFinder.php index fac7a49..98e179d 100644 --- a/src/FileFinder.php +++ b/src/FileFinder.php @@ -28,10 +28,10 @@ */ final class FileFinder implements \IteratorAggregate, \Countable { - const ONLY_FILE = 1; - const ONLY_DIR = 2; - const IGNORE_VCS_FILES = 1; - const IGNORE_DOT_FILES = 2; + public const ONLY_FILE = 1; + public const ONLY_DIR = 2; + public const IGNORE_VCS_FILES = 1; + public const IGNORE_DOT_FILES = 2; /** @var array */ private static $vcsPatterns = ['.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg']; diff --git a/src/FileSystem.php b/src/FileSystem.php index b88bac1..e6cd7c3 100644 --- a/src/FileSystem.php +++ b/src/FileSystem.php @@ -31,8 +31,8 @@ public static function isAbsPath(string $path): bool } if ( - $path{0} === '/' || // linux/mac - 1 === preg_match('#^[a-z]:[\/|\\\]{1}.+#i', $path) // windows + \strpos($path, '/') === 0 || // linux/mac + 1 === \preg_match('#^[a-z]:[\/|\\\]{1}.+#i', $path) // windows ) { return true; } @@ -63,9 +63,9 @@ public static function isAbsolutePath(string $file): bool */ public static function pathFormat(string $dirName): string { - $dirName = str_ireplace('\\', '/', trim($dirName)); + $dirName = (string)\str_ireplace('\\', '/', trim($dirName)); - return substr((string)$dirName, -1) === '/' ? $dirName : $dirName . '/'; + return \substr($dirName, -1) === '/' ? $dirName : $dirName . '/'; } /** @@ -239,10 +239,8 @@ public static function chown($files, string $user, $recursive = false) if (true !== lchown($file, $user)) { throw new IOException(sprintf('Failed to chown file "%s".', $file)); } - } else { - if (true !== chown($file, $user)) { - throw new IOException(sprintf('Failed to chown file "%s".', $file)); - } + } elseif (true !== chown($file, $user)) { + throw new IOException(sprintf('Failed to chown file "%s".', $file)); } } } @@ -255,7 +253,7 @@ public static function chown($files, string $user, $recursive = false) */ public static function getIterator(string $srcDir, callable $filter): \RecursiveIteratorIterator { - if (!$srcDir || !file_exists($srcDir)) { + if (!$srcDir || !\file_exists($srcDir)) { throw new \InvalidArgumentException('Please provide a exists source directory.'); }