fix:更新已知bug,优化代码

This commit is contained in:
Ying
2022-11-28 19:11:12 +08:00
parent f6aee95cfc
commit 9445b206a2
1378 changed files with 53759 additions and 20789 deletions

View File

@@ -23,7 +23,7 @@ namespace Symfony\Component\Finder\Iterator;
*/
class CustomFilterIterator extends \FilterIterator
{
private $filters = [];
private array $filters = [];
/**
* @param \Iterator<string, \SplFileInfo> $iterator The Iterator to filter
@@ -45,11 +45,8 @@ class CustomFilterIterator extends \FilterIterator
/**
* Filters the iterator values.
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function accept()
public function accept(): bool
{
$fileinfo = $this->current();

View File

@@ -22,7 +22,7 @@ use Symfony\Component\Finder\Comparator\DateComparator;
*/
class DateRangeFilterIterator extends \FilterIterator
{
private $comparators = [];
private array $comparators = [];
/**
* @param \Iterator<string, \SplFileInfo> $iterator
@@ -37,11 +37,8 @@ class DateRangeFilterIterator extends \FilterIterator
/**
* Filters the iterator values.
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function accept()
public function accept(): bool
{
$fileinfo = $this->current();

View File

@@ -23,7 +23,7 @@ namespace Symfony\Component\Finder\Iterator;
*/
class DepthRangeFilterIterator extends \FilterIterator
{
private $minDepth = 0;
private int $minDepth = 0;
/**
* @param \RecursiveIteratorIterator<\RecursiveIterator<TKey, TValue>> $iterator The Iterator to filter
@@ -40,11 +40,8 @@ class DepthRangeFilterIterator extends \FilterIterator
/**
* Filters the iterator values.
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function accept()
public function accept(): bool
{
return $this->getInnerIterator()->getDepth() >= $this->minDepth;
}

View File

@@ -21,10 +21,10 @@ namespace Symfony\Component\Finder\Iterator;
*/
class ExcludeDirectoryFilterIterator extends \FilterIterator implements \RecursiveIterator
{
private $iterator;
private $isRecursive;
private $excludedDirs = [];
private $excludedPattern;
private \Iterator $iterator;
private bool $isRecursive;
private array $excludedDirs = [];
private ?string $excludedPattern = null;
/**
* @param \Iterator $iterator The Iterator to filter
@@ -52,11 +52,8 @@ class ExcludeDirectoryFilterIterator extends \FilterIterator implements \Recursi
/**
* Filters the iterator values.
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function accept()
public function accept(): bool
{
if ($this->isRecursive && isset($this->excludedDirs[$this->getFilename()]) && $this->isDir()) {
return false;
@@ -72,20 +69,12 @@ class ExcludeDirectoryFilterIterator extends \FilterIterator implements \Recursi
return true;
}
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function hasChildren()
public function hasChildren(): bool
{
return $this->isRecursive && $this->iterator->hasChildren();
}
/**
* @return self
*/
#[\ReturnTypeWillChange]
public function getChildren()
public function getChildren(): self
{
$children = new self($this->iterator->getChildren(), []);
$children->excludedDirs = $this->excludedDirs;

View File

@@ -23,7 +23,7 @@ class FileTypeFilterIterator extends \FilterIterator
public const ONLY_FILES = 1;
public const ONLY_DIRECTORIES = 2;
private $mode;
private int $mode;
/**
* @param \Iterator $iterator The Iterator to filter
@@ -38,11 +38,8 @@ class FileTypeFilterIterator extends \FilterIterator
/**
* Filters the iterator values.
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function accept()
public function accept(): bool
{
$fileinfo = $this->current();
if (self::ONLY_DIRECTORIES === (self::ONLY_DIRECTORIES & $this->mode) && $fileinfo->isFile()) {

View File

@@ -23,11 +23,8 @@ class FilecontentFilterIterator extends MultiplePcreFilterIterator
{
/**
* Filters the iterator values.
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function accept()
public function accept(): bool
{
if (!$this->matchRegexps && !$this->noMatchRegexps) {
return true;
@@ -51,10 +48,8 @@ class FilecontentFilterIterator extends MultiplePcreFilterIterator
* Converts string to regexp if necessary.
*
* @param string $str Pattern: string or regexp
*
* @return string
*/
protected function toRegex(string $str)
protected function toRegex(string $str): string
{
return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
}

View File

@@ -24,11 +24,8 @@ class FilenameFilterIterator extends MultiplePcreFilterIterator
{
/**
* Filters the iterator values.
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function accept()
public function accept(): bool
{
return $this->isAccepted($this->current()->getFilename());
}
@@ -40,10 +37,8 @@ class FilenameFilterIterator extends MultiplePcreFilterIterator
* Glob strings are transformed with Glob::toRegex().
*
* @param string $str Pattern: glob or regexp
*
* @return string
*/
protected function toRegex(string $str)
protected function toRegex(string $str): string
{
return $this->isRegex($str) ? $str : Glob::toRegex($str);
}

View File

@@ -18,11 +18,11 @@ namespace Symfony\Component\Finder\Iterator;
*/
class LazyIterator implements \IteratorAggregate
{
private $iteratorFactory;
private \Closure $iteratorFactory;
public function __construct(callable $iteratorFactory)
{
$this->iteratorFactory = $iteratorFactory;
$this->iteratorFactory = $iteratorFactory instanceof \Closure ? $iteratorFactory : \Closure::fromCallable($iteratorFactory);
}
public function getIterator(): \Traversable

View File

@@ -50,10 +50,8 @@ abstract class MultiplePcreFilterIterator extends \FilterIterator
* If there is no regexps defined in the class, this method will accept the string.
* Such case can be handled by child classes before calling the method if they want to
* apply a different behavior.
*
* @return bool
*/
protected function isAccepted(string $string)
protected function isAccepted(string $string): bool
{
// should at least not match one rule to exclude
foreach ($this->noMatchRegexps as $regex) {
@@ -79,10 +77,8 @@ abstract class MultiplePcreFilterIterator extends \FilterIterator
/**
* Checks whether the string is a regex.
*
* @return bool
*/
protected function isRegex(string $str)
protected function isRegex(string $str): bool
{
$availableModifiers = 'imsxuADU';
@@ -110,8 +106,6 @@ abstract class MultiplePcreFilterIterator extends \FilterIterator
/**
* Converts string into regexp.
*
* @return string
*/
abstract protected function toRegex(string $str);
abstract protected function toRegex(string $str): string;
}

View File

@@ -23,11 +23,8 @@ class PathFilterIterator extends MultiplePcreFilterIterator
{
/**
* Filters the iterator values.
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function accept()
public function accept(): bool
{
$filename = $this->current()->getRelativePathname();
@@ -49,10 +46,8 @@ class PathFilterIterator extends MultiplePcreFilterIterator
* Use only / as directory separator (on Windows also).
*
* @param string $str Pattern: regexp or dirname
*
* @return string
*/
protected function toRegex(string $str)
protected function toRegex(string $str): string
{
return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
}

View File

@@ -21,20 +21,13 @@ use Symfony\Component\Finder\SplFileInfo;
*/
class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
{
/**
* @var bool
*/
private $ignoreUnreadableDirs;
/**
* @var bool
*/
private $rewindable;
private bool $ignoreUnreadableDirs;
private ?bool $rewindable = null;
// these 3 properties take part of the performance optimization to avoid redoing the same work in all iterations
private $rootPath;
private $subPath;
private $directorySeparator = '/';
private string $rootPath;
private string $subPath;
private string $directorySeparator = '/';
/**
* @throws \RuntimeException
@@ -55,17 +48,15 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
/**
* Return an instance of SplFileInfo with support for relative paths.
*
* @return SplFileInfo
*/
#[\ReturnTypeWillChange]
public function current()
public function current(): SplFileInfo
{
// the logic here avoids redoing the same work in all iterations
if (null === $subPathname = $this->subPath) {
$subPathname = $this->subPath = $this->getSubPath();
if (!isset($this->subPath)) {
$this->subPath = $this->getSubPath();
}
$subPathname = $this->subPath;
if ('' !== $subPathname) {
$subPathname .= $this->directorySeparator;
}
@@ -78,13 +69,7 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
return new SplFileInfo($basePath.$subPathname, $this->subPath, $subPathname);
}
/**
* @param bool $allowLinks
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function hasChildren($allowLinks = false)
public function hasChildren(bool $allowLinks = false): bool
{
$hasChildren = parent::hasChildren($allowLinks);
@@ -103,12 +88,9 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
}
/**
* @return \RecursiveDirectoryIterator
*
* @throws AccessDeniedException
*/
#[\ReturnTypeWillChange]
public function getChildren()
public function getChildren(): \RecursiveDirectoryIterator
{
try {
$children = parent::getChildren();
@@ -130,11 +112,8 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
/**
* Do nothing for non rewindable stream.
*
* @return void
*/
#[\ReturnTypeWillChange]
public function rewind()
public function rewind(): void
{
if (false === $this->isRewindable()) {
return;
@@ -145,10 +124,8 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
/**
* Checks if the stream is rewindable.
*
* @return bool
*/
public function isRewindable()
public function isRewindable(): bool
{
if (null !== $this->rewindable) {
return $this->rewindable;

View File

@@ -22,7 +22,7 @@ use Symfony\Component\Finder\Comparator\NumberComparator;
*/
class SizeRangeFilterIterator extends \FilterIterator
{
private $comparators = [];
private array $comparators = [];
/**
* @param \Iterator<string, \SplFileInfo> $iterator
@@ -37,11 +37,8 @@ class SizeRangeFilterIterator extends \FilterIterator
/**
* Filters the iterator values.
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function accept()
public function accept(): bool
{
$fileinfo = $this->current();
if (!$fileinfo->isFile()) {

View File

@@ -28,8 +28,8 @@ class SortableIterator implements \IteratorAggregate
public const SORT_BY_MODIFIED_TIME = 5;
public const SORT_BY_NAME_NATURAL = 6;
private $iterator;
private $sort;
private \Traversable $iterator;
private \Closure|int $sort;
/**
* @param \Traversable<string, \SplFileInfo> $iterator
@@ -37,7 +37,7 @@ class SortableIterator implements \IteratorAggregate
*
* @throws \InvalidArgumentException
*/
public function __construct(\Traversable $iterator, $sort, bool $reverseOrder = false)
public function __construct(\Traversable $iterator, int|callable $sort, bool $reverseOrder = false)
{
$this->iterator = $iterator;
$order = $reverseOrder ? -1 : 1;
@@ -75,17 +75,13 @@ class SortableIterator implements \IteratorAggregate
} elseif (self::SORT_BY_NONE === $sort) {
$this->sort = $order;
} elseif (\is_callable($sort)) {
$this->sort = $reverseOrder ? static function (\SplFileInfo $a, \SplFileInfo $b) use ($sort) { return -$sort($a, $b); } : $sort;
$this->sort = $reverseOrder ? static function (\SplFileInfo $a, \SplFileInfo $b) use ($sort) { return -$sort($a, $b); } : \Closure::fromCallable($sort);
} else {
throw new \InvalidArgumentException('The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.');
}
}
/**
* @return \Traversable<string, \SplFileInfo>
*/
#[\ReturnTypeWillChange]
public function getIterator()
public function getIterator(): \Traversable
{
if (1 === $this->sort) {
return $this->iterator;