Skip to content

Commit b53b3b3

Browse files
committed
Implement faster FilteredRecursiveDirectoryIterator
fix cs use ReturnTypeWillChange Removed debug out Typo
1 parent 0c27060 commit b53b3b3

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace PHP_Parallel_Lint\PhpParallelLint\Iterators;
4+
5+
use ReturnTypeWillChange;
6+
7+
class FilteredRecursiveDirectoryIterator extends \RecursiveDirectoryIterator
8+
{
9+
private $excluded = array();
10+
11+
public function __construct($path, $flags = null, array $excluded = array())
12+
{
13+
$this->excluded = $excluded;
14+
15+
if ($flags === null) {
16+
$flags = \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO;
17+
}
18+
19+
parent::__construct($path, $flags);
20+
}
21+
22+
#[ReturnTypeWillChange]
23+
public function hasChildren($allowLinks = false)
24+
{
25+
if (in_array($this->getBasename(), $this->excluded)) {
26+
return false;
27+
}
28+
29+
return parent::hasChildren($allowLinks);
30+
}
31+
}

src/Manager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHP_Parallel_Lint\PhpParallelLint\Exceptions\ClassNotFoundException;
1010
use PHP_Parallel_Lint\PhpParallelLint\Exceptions\ParallelLintException;
1111
use PHP_Parallel_Lint\PhpParallelLint\Exceptions\PathNotFoundException;
12+
use PHP_Parallel_Lint\PhpParallelLint\Iterators\FilteredRecursiveDirectoryIterator;
1213
use PHP_Parallel_Lint\PhpParallelLint\Iterators\RecursiveDirectoryFilterIterator;
1314
use PHP_Parallel_Lint\PhpParallelLint\Outputs\CheckstyleOutput;
1415
use PHP_Parallel_Lint\PhpParallelLint\Outputs\GitLabOutput;
@@ -163,7 +164,7 @@ protected function getFilesFromPaths(array $paths, array $extensions, array $exc
163164
if (is_file($path)) {
164165
$files[] = $path;
165166
} elseif (is_dir($path)) {
166-
$iterator = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
167+
$iterator = new FilteredRecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS, $excluded);
167168
if (!empty($excluded)) {
168169
$iterator = new RecursiveDirectoryFilterIterator($iterator, $excluded);
169170
}

0 commit comments

Comments
 (0)