Skip to content

Commit 7b09d72

Browse files
jrfnlgrogy
authored andcommitted
PHP 8.1: silence the deprecation notice about RecursiveFilterIterator method return types
As of PHP 8.1, PHP adds return type declarations to the PHP native functions. For the `RecursiveFilterIterator`, the relevant method signatures are: * `accept(): bool` * `hasChildren(): bool` * `getChildren(): ?RecursiveFilterIterator` As this libary still supports PHP 5.3, it is not possible to add this return type as: 1. Return types weren't available until PHP 7.0 and 2. the `mixed` return type only became available in PHP 8.0. For libraries still supporting PHP < 7.0, there are two choices: 1. Either decouple from the interface. 2. Or use a PHP 8.1 attribute to silence the deprecation notice. As prior to PHP 8.0, attributes are ignored as if they were comments, it is safe to add the attribute to the library and IMO, this is prefered over decoupling the classes from the interface. To prevent PHPCS tripping up over "something" existing between the function docblock and the declaration, PHPCS 3.6.0 should be used, which is the first PHPCS version with full PHP 8.0 syntax support in the sniffs (albeit that there are still some small things to fix up in PHPCS). Refs: * https://wiki.php.net/rfc/internal_method_return_types
1 parent 49cc975 commit 7b09d72

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Manager.php

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use JakubOnderka\PhpParallelLint\Contracts\SyntaxErrorCallback;
55
use JakubOnderka\PhpParallelLint\Process\GitBlameProcess;
66
use JakubOnderka\PhpParallelLint\Process\PhpExecutable;
7+
use ReturnTypeWillChange;
78

89
class Manager
910
{
@@ -226,6 +227,7 @@ public function __construct(\RecursiveDirectoryIterator $iterator, array $exclud
226227
* @link http://php.net/manual/en/filteriterator.accept.php
227228
* @return bool true if the current element is acceptable, otherwise false.
228229
*/
230+
#[ReturnTypeWillChange]
229231
public function accept()
230232
{
231233
$current = $this->current()->getPathname();
@@ -245,6 +247,7 @@ public function accept()
245247
* @link http://php.net/manual/en/recursivefilteriterator.haschildren.php
246248
* @return bool true if the inner iterator has children, otherwise false
247249
*/
250+
#[ReturnTypeWillChange]
248251
public function hasChildren()
249252
{
250253
return $this->iterator->hasChildren();
@@ -257,6 +260,7 @@ public function hasChildren()
257260
* @link http://php.net/manual/en/recursivefilteriterator.getchildren.php
258261
* @return \RecursiveFilterIterator containing the inner iterator's children.
259262
*/
263+
#[ReturnTypeWillChange]
260264
public function getChildren()
261265
{
262266
return new self($this->iterator->getChildren(), $this->excluded);

0 commit comments

Comments
 (0)