[5.0][Finder] add parameter type-hints
This commit is contained in:
parent
a25848b2b5
commit
7f98903d05
@ -31,12 +31,7 @@ class Comparator
|
|||||||
return $this->target;
|
return $this->target;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function setTarget(string $target)
|
||||||
* Sets the target value.
|
|
||||||
*
|
|
||||||
* @param string $target The target value
|
|
||||||
*/
|
|
||||||
public function setTarget($target)
|
|
||||||
{
|
{
|
||||||
$this->target = $target;
|
$this->target = $target;
|
||||||
}
|
}
|
||||||
@ -54,13 +49,11 @@ class Comparator
|
|||||||
/**
|
/**
|
||||||
* Sets the comparison operator.
|
* Sets the comparison operator.
|
||||||
*
|
*
|
||||||
* @param string $operator A valid operator
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function setOperator($operator)
|
public function setOperator(string $operator)
|
||||||
{
|
{
|
||||||
if (!$operator) {
|
if ('' === $operator) {
|
||||||
$operator = '==';
|
$operator = '==';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,13 +336,11 @@ class Finder implements \IteratorAggregate, \Countable
|
|||||||
*
|
*
|
||||||
* This option is enabled by default.
|
* This option is enabled by default.
|
||||||
*
|
*
|
||||||
* @param bool $ignoreDotFiles Whether to exclude "hidden" files or not
|
|
||||||
*
|
|
||||||
* @return $this
|
* @return $this
|
||||||
*
|
*
|
||||||
* @see ExcludeDirectoryFilterIterator
|
* @see ExcludeDirectoryFilterIterator
|
||||||
*/
|
*/
|
||||||
public function ignoreDotFiles($ignoreDotFiles)
|
public function ignoreDotFiles(bool $ignoreDotFiles)
|
||||||
{
|
{
|
||||||
if ($ignoreDotFiles) {
|
if ($ignoreDotFiles) {
|
||||||
$this->ignore |= static::IGNORE_DOT_FILES;
|
$this->ignore |= static::IGNORE_DOT_FILES;
|
||||||
@ -358,13 +356,11 @@ class Finder implements \IteratorAggregate, \Countable
|
|||||||
*
|
*
|
||||||
* This option is enabled by default.
|
* This option is enabled by default.
|
||||||
*
|
*
|
||||||
* @param bool $ignoreVCS Whether to exclude VCS files or not
|
|
||||||
*
|
|
||||||
* @return $this
|
* @return $this
|
||||||
*
|
*
|
||||||
* @see ExcludeDirectoryFilterIterator
|
* @see ExcludeDirectoryFilterIterator
|
||||||
*/
|
*/
|
||||||
public function ignoreVCS($ignoreVCS)
|
public function ignoreVCS(bool $ignoreVCS)
|
||||||
{
|
{
|
||||||
if ($ignoreVCS) {
|
if ($ignoreVCS) {
|
||||||
$this->ignore |= static::IGNORE_VCS_FILES;
|
$this->ignore |= static::IGNORE_VCS_FILES;
|
||||||
@ -432,8 +428,6 @@ class Finder implements \IteratorAggregate, \Countable
|
|||||||
*
|
*
|
||||||
* This can be slow as all the matching files and directories must be retrieved for comparison.
|
* This can be slow as all the matching files and directories must be retrieved for comparison.
|
||||||
*
|
*
|
||||||
* @param bool $useNaturalSort Whether to use natural sort or not, disabled by default
|
|
||||||
*
|
|
||||||
* @return $this
|
* @return $this
|
||||||
*
|
*
|
||||||
* @see SortableIterator
|
* @see SortableIterator
|
||||||
@ -563,13 +557,11 @@ class Finder implements \IteratorAggregate, \Countable
|
|||||||
*
|
*
|
||||||
* By default, scanning unreadable directories content throws an AccessDeniedException.
|
* By default, scanning unreadable directories content throws an AccessDeniedException.
|
||||||
*
|
*
|
||||||
* @param bool $ignore
|
|
||||||
*
|
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function ignoreUnreadableDirs($ignore = true)
|
public function ignoreUnreadableDirs(bool $ignore = true)
|
||||||
{
|
{
|
||||||
$this->ignoreUnreadableDirs = (bool) $ignore;
|
$this->ignoreUnreadableDirs = $ignore;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -577,7 +569,7 @@ class Finder implements \IteratorAggregate, \Countable
|
|||||||
/**
|
/**
|
||||||
* Searches files and directories which match defined rules.
|
* Searches files and directories which match defined rules.
|
||||||
*
|
*
|
||||||
* @param string|array $dirs A directory path or an array of directories
|
* @param string|string[] $dirs A directory path or an array of directories
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*
|
*
|
||||||
@ -644,7 +636,7 @@ class Finder implements \IteratorAggregate, \Countable
|
|||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException when the given argument is not iterable
|
* @throws \InvalidArgumentException when the given argument is not iterable
|
||||||
*/
|
*/
|
||||||
public function append($iterator)
|
public function append(iterable $iterator)
|
||||||
{
|
{
|
||||||
if ($iterator instanceof \IteratorAggregate) {
|
if ($iterator instanceof \IteratorAggregate) {
|
||||||
$this->iterators[] = $iterator->getIterator();
|
$this->iterators[] = $iterator->getIterator();
|
||||||
@ -789,11 +781,9 @@ class Finder implements \IteratorAggregate, \Countable
|
|||||||
*
|
*
|
||||||
* Excluding: (s)ftp:// wrapper
|
* Excluding: (s)ftp:// wrapper
|
||||||
*
|
*
|
||||||
* @param string $dir
|
|
||||||
*
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function normalizeDir($dir)
|
private function normalizeDir(string $dir)
|
||||||
{
|
{
|
||||||
$dir = rtrim($dir, '/'.\DIRECTORY_SEPARATOR);
|
$dir = rtrim($dir, '/'.\DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
|
@ -38,14 +38,9 @@ class Glob
|
|||||||
/**
|
/**
|
||||||
* Returns a regexp which is the equivalent of the glob pattern.
|
* Returns a regexp which is the equivalent of the glob pattern.
|
||||||
*
|
*
|
||||||
* @param string $glob The glob pattern
|
* @return string
|
||||||
* @param bool $strictLeadingDot
|
|
||||||
* @param bool $strictWildcardSlash
|
|
||||||
* @param string $delimiter Optional delimiter
|
|
||||||
*
|
|
||||||
* @return string regex The regexp
|
|
||||||
*/
|
*/
|
||||||
public static function toRegex($glob, $strictLeadingDot = true, $strictWildcardSlash = true, $delimiter = '#')
|
public static function toRegex(string $glob, bool $strictLeadingDot = true, bool $strictWildcardSlash = true, string $delimiter = '#')
|
||||||
{
|
{
|
||||||
$firstByte = true;
|
$firstByte = true;
|
||||||
$escaping = false;
|
$escaping = false;
|
||||||
|
@ -25,7 +25,7 @@ class ExcludeDirectoryFilterIterator extends \FilterIterator implements \Recursi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Iterator $iterator The Iterator to filter
|
* @param \Iterator $iterator The Iterator to filter
|
||||||
* @param array $directories An array of directories to exclude
|
* @param string[] $directories An array of directories to exclude
|
||||||
*/
|
*/
|
||||||
public function __construct(\Iterator $iterator, array $directories)
|
public function __construct(\Iterator $iterator, array $directories)
|
||||||
{
|
{
|
||||||
|
@ -51,7 +51,7 @@ class FilecontentFilterIterator extends MultiplePcreFilterIterator
|
|||||||
*
|
*
|
||||||
* @return string regexp corresponding to a given string or regexp
|
* @return string regexp corresponding to a given string or regexp
|
||||||
*/
|
*/
|
||||||
protected function toRegex($str)
|
protected function toRegex(string $str)
|
||||||
{
|
{
|
||||||
return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
|
return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ class FilenameFilterIterator extends MultiplePcreFilterIterator
|
|||||||
*
|
*
|
||||||
* @return string regexp corresponding to a given glob or regexp
|
* @return string regexp corresponding to a given glob or regexp
|
||||||
*/
|
*/
|
||||||
protected function toRegex($str)
|
protected function toRegex(string $str)
|
||||||
{
|
{
|
||||||
return $this->isRegex($str) ? $str : Glob::toRegex($str);
|
return $this->isRegex($str) ? $str : Glob::toRegex($str);
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,8 @@ abstract class MultiplePcreFilterIterator extends \FilterIterator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Iterator $iterator The Iterator to filter
|
* @param \Iterator $iterator The Iterator to filter
|
||||||
* @param array $matchPatterns An array of patterns that need to match
|
* @param string[] $matchPatterns An array of patterns that need to match
|
||||||
* @param array $noMatchPatterns An array of patterns that need to not match
|
* @param string[] $noMatchPatterns An array of patterns that need to not match
|
||||||
*/
|
*/
|
||||||
public function __construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns)
|
public function __construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns)
|
||||||
{
|
{
|
||||||
@ -46,11 +46,9 @@ abstract class MultiplePcreFilterIterator extends \FilterIterator
|
|||||||
* Such case can be handled by child classes before calling the method if they want to
|
* Such case can be handled by child classes before calling the method if they want to
|
||||||
* apply a different behavior.
|
* apply a different behavior.
|
||||||
*
|
*
|
||||||
* @param string $string The string to be matched against filters
|
|
||||||
*
|
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function isAccepted($string)
|
protected function isAccepted(string $string)
|
||||||
{
|
{
|
||||||
// should at least not match one rule to exclude
|
// should at least not match one rule to exclude
|
||||||
foreach ($this->noMatchRegexps as $regex) {
|
foreach ($this->noMatchRegexps as $regex) {
|
||||||
@ -77,11 +75,9 @@ abstract class MultiplePcreFilterIterator extends \FilterIterator
|
|||||||
/**
|
/**
|
||||||
* Checks whether the string is a regex.
|
* Checks whether the string is a regex.
|
||||||
*
|
*
|
||||||
* @param string $str
|
* @return bool
|
||||||
*
|
|
||||||
* @return bool Whether the given string is a regex
|
|
||||||
*/
|
*/
|
||||||
protected function isRegex($str)
|
protected function isRegex(string $str)
|
||||||
{
|
{
|
||||||
if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) {
|
if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) {
|
||||||
$start = substr($m[1], 0, 1);
|
$start = substr($m[1], 0, 1);
|
||||||
@ -104,9 +100,7 @@ abstract class MultiplePcreFilterIterator extends \FilterIterator
|
|||||||
/**
|
/**
|
||||||
* Converts string into regexp.
|
* Converts string into regexp.
|
||||||
*
|
*
|
||||||
* @param string $str Pattern
|
* @return string
|
||||||
*
|
|
||||||
* @return string regexp corresponding to a given string
|
|
||||||
*/
|
*/
|
||||||
abstract protected function toRegex($str);
|
abstract protected function toRegex(string $str);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ class PathFilterIterator extends MultiplePcreFilterIterator
|
|||||||
*
|
*
|
||||||
* @return string regexp corresponding to a given string or regexp
|
* @return string regexp corresponding to a given string or regexp
|
||||||
*/
|
*/
|
||||||
protected function toRegex($str)
|
protected function toRegex(string $str)
|
||||||
{
|
{
|
||||||
return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
|
return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
|
||||||
}
|
}
|
||||||
|
@ -41,15 +41,15 @@ class SortableIterator implements \IteratorAggregate
|
|||||||
$order = $reverseOrder ? -1 : 1;
|
$order = $reverseOrder ? -1 : 1;
|
||||||
|
|
||||||
if (self::SORT_BY_NAME === $sort) {
|
if (self::SORT_BY_NAME === $sort) {
|
||||||
$this->sort = function ($a, $b) use ($order) {
|
$this->sort = function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||||
return $order * strcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
|
return $order * strcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
|
||||||
};
|
};
|
||||||
} elseif (self::SORT_BY_NAME_NATURAL === $sort) {
|
} elseif (self::SORT_BY_NAME_NATURAL === $sort) {
|
||||||
$this->sort = function ($a, $b) use ($order) {
|
$this->sort = function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||||
return $order * strnatcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
|
return $order * strnatcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
|
||||||
};
|
};
|
||||||
} elseif (self::SORT_BY_TYPE === $sort) {
|
} elseif (self::SORT_BY_TYPE === $sort) {
|
||||||
$this->sort = function ($a, $b) use ($order) {
|
$this->sort = function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||||
if ($a->isDir() && $b->isFile()) {
|
if ($a->isDir() && $b->isFile()) {
|
||||||
return -$order;
|
return -$order;
|
||||||
} elseif ($a->isFile() && $b->isDir()) {
|
} elseif ($a->isFile() && $b->isDir()) {
|
||||||
@ -59,21 +59,21 @@ class SortableIterator implements \IteratorAggregate
|
|||||||
return $order * strcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
|
return $order * strcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
|
||||||
};
|
};
|
||||||
} elseif (self::SORT_BY_ACCESSED_TIME === $sort) {
|
} elseif (self::SORT_BY_ACCESSED_TIME === $sort) {
|
||||||
$this->sort = function ($a, $b) use ($order) {
|
$this->sort = function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||||
return $order * ($a->getATime() - $b->getATime());
|
return $order * ($a->getATime() - $b->getATime());
|
||||||
};
|
};
|
||||||
} elseif (self::SORT_BY_CHANGED_TIME === $sort) {
|
} elseif (self::SORT_BY_CHANGED_TIME === $sort) {
|
||||||
$this->sort = function ($a, $b) use ($order) {
|
$this->sort = function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||||
return $order * ($a->getCTime() - $b->getCTime());
|
return $order * ($a->getCTime() - $b->getCTime());
|
||||||
};
|
};
|
||||||
} elseif (self::SORT_BY_MODIFIED_TIME === $sort) {
|
} elseif (self::SORT_BY_MODIFIED_TIME === $sort) {
|
||||||
$this->sort = function ($a, $b) use ($order) {
|
$this->sort = function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||||
return $order * ($a->getMTime() - $b->getMTime());
|
return $order * ($a->getMTime() - $b->getMTime());
|
||||||
};
|
};
|
||||||
} elseif (self::SORT_BY_NONE === $sort) {
|
} elseif (self::SORT_BY_NONE === $sort) {
|
||||||
$this->sort = $order;
|
$this->sort = $order;
|
||||||
} elseif (\is_callable($sort)) {
|
} elseif (\is_callable($sort)) {
|
||||||
$this->sort = $reverseOrder ? function ($a, $b) use ($sort) { return -$sort($a, $b); }
|
$this->sort = $reverseOrder ? function (\SplFileInfo $a, \SplFileInfo $b) use ($sort) { return -$sort($a, $b); }
|
||||||
: $sort;
|
: $sort;
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException('The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.');
|
throw new \InvalidArgumentException('The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.');
|
||||||
|
@ -59,12 +59,12 @@ class TestMultiplePcreFilterIterator extends MultiplePcreFilterIterator
|
|||||||
throw new \BadFunctionCallException('Not implemented');
|
throw new \BadFunctionCallException('Not implemented');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isRegex($str)
|
public function isRegex(string $str)
|
||||||
{
|
{
|
||||||
return parent::isRegex($str);
|
return parent::isRegex($str);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toRegex($str)
|
public function toRegex(string $str)
|
||||||
{
|
{
|
||||||
throw new \BadFunctionCallException('Not implemented');
|
throw new \BadFunctionCallException('Not implemented');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user