From 70362f1e112280d75b30087c7598b837c1b468b6 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 26 Jul 2021 15:29:22 +0200 Subject: [PATCH] Fix return types for PHP 8.1 --- Finder.php | 2 ++ Iterator/CustomFilterIterator.php | 1 + Iterator/DateRangeFilterIterator.php | 1 + Iterator/DepthRangeFilterIterator.php | 1 + Iterator/ExcludeDirectoryFilterIterator.php | 3 +++ Iterator/FileTypeFilterIterator.php | 1 + Iterator/FilecontentFilterIterator.php | 1 + Iterator/FilenameFilterIterator.php | 1 + Iterator/PathFilterIterator.php | 1 + Iterator/SizeRangeFilterIterator.php | 1 + Iterator/SortableIterator.php | 1 + Tests/Iterator/Iterator.php | 14 +++++++++++--- Tests/Iterator/MultiplePcreFilterIteratorTest.php | 2 +- 13 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Finder.php b/Finder.php index 92249ad9..e1194ed6 100644 --- a/Finder.php +++ b/Finder.php @@ -618,6 +618,7 @@ public function in($dirs) * * @throws \LogicException if the in() method has not been called */ + #[\ReturnTypeWillChange] public function getIterator() { if (0 === \count($this->dirs) && 0 === \count($this->iterators)) { @@ -702,6 +703,7 @@ public function hasResults() * * @return int */ + #[\ReturnTypeWillChange] public function count() { return iterator_count($this->getIterator()); diff --git a/Iterator/CustomFilterIterator.php b/Iterator/CustomFilterIterator.php index a30bbd0b..f85cb7bf 100644 --- a/Iterator/CustomFilterIterator.php +++ b/Iterator/CustomFilterIterator.php @@ -46,6 +46,7 @@ public function __construct(\Iterator $iterator, array $filters) * * @return bool true if the value should be kept, false otherwise */ + #[\ReturnTypeWillChange] public function accept() { $fileinfo = $this->current(); diff --git a/Iterator/DateRangeFilterIterator.php b/Iterator/DateRangeFilterIterator.php index 2e97e00d..90616f47 100644 --- a/Iterator/DateRangeFilterIterator.php +++ b/Iterator/DateRangeFilterIterator.php @@ -38,6 +38,7 @@ public function __construct(\Iterator $iterator, array $comparators) * * @return bool true if the value should be kept, false otherwise */ + #[\ReturnTypeWillChange] public function accept() { $fileinfo = $this->current(); diff --git a/Iterator/DepthRangeFilterIterator.php b/Iterator/DepthRangeFilterIterator.php index 18e751d7..e96fefd9 100644 --- a/Iterator/DepthRangeFilterIterator.php +++ b/Iterator/DepthRangeFilterIterator.php @@ -38,6 +38,7 @@ public function __construct(\RecursiveIteratorIterator $iterator, int $minDepth * * @return bool true if the value should be kept, false otherwise */ + #[\ReturnTypeWillChange] public function accept() { return $this->getInnerIterator()->getDepth() >= $this->minDepth; diff --git a/Iterator/ExcludeDirectoryFilterIterator.php b/Iterator/ExcludeDirectoryFilterIterator.php index 366ad70c..cf9e6787 100644 --- a/Iterator/ExcludeDirectoryFilterIterator.php +++ b/Iterator/ExcludeDirectoryFilterIterator.php @@ -52,6 +52,7 @@ public function __construct(\Iterator $iterator, array $directories) * * @return bool True if the value should be kept, false otherwise */ + #[\ReturnTypeWillChange] public function accept() { if ($this->isRecursive && isset($this->excludedDirs[$this->getFilename()]) && $this->isDir()) { @@ -71,6 +72,7 @@ public function accept() /** * @return bool */ + #[\ReturnTypeWillChange] public function hasChildren() { return $this->isRecursive && $this->iterator->hasChildren(); @@ -79,6 +81,7 @@ public function hasChildren() /** * @return self */ + #[\ReturnTypeWillChange] public function getChildren() { $children = new self($this->iterator->getChildren(), []); diff --git a/Iterator/FileTypeFilterIterator.php b/Iterator/FileTypeFilterIterator.php index 0ea2c508..d054cefb 100644 --- a/Iterator/FileTypeFilterIterator.php +++ b/Iterator/FileTypeFilterIterator.php @@ -39,6 +39,7 @@ public function __construct(\Iterator $iterator, int $mode) * * @return bool true if the value should be kept, false otherwise */ + #[\ReturnTypeWillChange] public function accept() { $fileinfo = $this->current(); diff --git a/Iterator/FilecontentFilterIterator.php b/Iterator/FilecontentFilterIterator.php index 81594b87..41eb767f 100644 --- a/Iterator/FilecontentFilterIterator.php +++ b/Iterator/FilecontentFilterIterator.php @@ -24,6 +24,7 @@ class FilecontentFilterIterator extends MultiplePcreFilterIterator * * @return bool true if the value should be kept, false otherwise */ + #[\ReturnTypeWillChange] public function accept() { if (!$this->matchRegexps && !$this->noMatchRegexps) { diff --git a/Iterator/FilenameFilterIterator.php b/Iterator/FilenameFilterIterator.php index e168cd8f..8365756c 100644 --- a/Iterator/FilenameFilterIterator.php +++ b/Iterator/FilenameFilterIterator.php @@ -25,6 +25,7 @@ class FilenameFilterIterator extends MultiplePcreFilterIterator * * @return bool true if the value should be kept, false otherwise */ + #[\ReturnTypeWillChange] public function accept() { return $this->isAccepted($this->current()->getFilename()); diff --git a/Iterator/PathFilterIterator.php b/Iterator/PathFilterIterator.php index 3fda557b..f4aaa1fb 100644 --- a/Iterator/PathFilterIterator.php +++ b/Iterator/PathFilterIterator.php @@ -24,6 +24,7 @@ class PathFilterIterator extends MultiplePcreFilterIterator * * @return bool true if the value should be kept, false otherwise */ + #[\ReturnTypeWillChange] public function accept() { $filename = $this->current()->getRelativePathname(); diff --git a/Iterator/SizeRangeFilterIterator.php b/Iterator/SizeRangeFilterIterator.php index 2aeef67b..4078f369 100644 --- a/Iterator/SizeRangeFilterIterator.php +++ b/Iterator/SizeRangeFilterIterator.php @@ -38,6 +38,7 @@ public function __construct(\Iterator $iterator, array $comparators) * * @return bool true if the value should be kept, false otherwise */ + #[\ReturnTypeWillChange] public function accept() { $fileinfo = $this->current(); diff --git a/Iterator/SortableIterator.php b/Iterator/SortableIterator.php index 8559ba51..adc7e999 100644 --- a/Iterator/SortableIterator.php +++ b/Iterator/SortableIterator.php @@ -81,6 +81,7 @@ public function __construct(\Traversable $iterator, $sort, bool $reverseOrder = /** * @return \Traversable */ + #[\ReturnTypeWillChange] public function getIterator() { if (1 === $this->sort) { diff --git a/Tests/Iterator/Iterator.php b/Tests/Iterator/Iterator.php index bc2eb53b..108c66a2 100644 --- a/Tests/Iterator/Iterator.php +++ b/Tests/Iterator/Iterator.php @@ -23,12 +23,12 @@ public function __construct(array $values = []) $this->rewind(); } - public function attach(\SplFileInfo $fileinfo) + public function attach(\SplFileInfo $fileinfo): void { $this->values[] = $fileinfo; } - public function rewind() + public function rewind(): void { reset($this->values); } @@ -38,16 +38,24 @@ public function valid(): bool return false !== $this->current(); } - public function next() + public function next(): void { next($this->values); } + /** + * @return mixed + */ + #[\ReturnTypeWillChange] public function current() { return current($this->values); } + /** + * @return mixed + */ + #[\ReturnTypeWillChange] public function key() { return key($this->values); diff --git a/Tests/Iterator/MultiplePcreFilterIteratorTest.php b/Tests/Iterator/MultiplePcreFilterIteratorTest.php index 15e069b9..590aea21 100644 --- a/Tests/Iterator/MultiplePcreFilterIteratorTest.php +++ b/Tests/Iterator/MultiplePcreFilterIteratorTest.php @@ -54,7 +54,7 @@ public function __construct() { } - public function accept() + public function accept(): bool { throw new \BadFunctionCallException('Not implemented'); }