11
11
12
12
use function array_filter ;
13
13
use function array_map ;
14
+ use function array_values ;
15
+ use function assert ;
14
16
use function preg_match ;
15
17
use function realpath ;
16
18
use function str_ends_with ;
17
19
use function str_replace ;
18
20
use function str_starts_with ;
19
21
use FilterIterator ;
22
+ use SplFileInfo ;
20
23
21
24
/**
22
25
* @internal This class is not covered by the backward compatibility promise for phpunit/php-file-iterator
@@ -27,23 +30,43 @@ final class Iterator extends FilterIterator
27
30
28
31
public const SUFFIX = 1 ;
29
32
private string |false $ basePath ;
33
+
34
+ /**
35
+ * @psalm-var list<string>
36
+ */
30
37
private array $ suffixes ;
38
+
39
+ /**
40
+ * @psalm-var list<string>
41
+ */
31
42
private array $ prefixes ;
43
+
44
+ /**
45
+ * @psalm-var list<string>
46
+ */
32
47
private array $ exclude ;
33
48
49
+ /**
50
+ * @psalm-param list<string> $suffixes
51
+ * @psalm-param list<string> $prefixes
52
+ * @psalm-param list<string> $exclude
53
+ */
34
54
public function __construct (string $ basePath , \Iterator $ iterator , array $ suffixes = [], array $ prefixes = [], array $ exclude = [])
35
55
{
36
56
$ this ->basePath = realpath ($ basePath );
37
57
$ this ->prefixes = $ prefixes ;
38
58
$ this ->suffixes = $ suffixes ;
39
- $ this ->exclude = array_filter (array_map ('realpath ' , $ exclude ));
59
+ $ this ->exclude = array_values ( array_filter (array_map ('realpath ' , $ exclude) ));
40
60
41
61
parent ::__construct ($ iterator );
42
62
}
43
63
44
64
public function accept (): bool
45
65
{
46
- $ current = $ this ->getInnerIterator ()->current ();
66
+ $ current = $ this ->getInnerIterator ()->current ();
67
+
68
+ assert ($ current instanceof SplFileInfo);
69
+
47
70
$ filename = $ current ->getFilename ();
48
71
$ realPath = $ current ->getRealPath ();
49
72
@@ -61,7 +84,7 @@ public function accept(): bool
61
84
private function acceptPath (string $ path ): bool
62
85
{
63
86
// Filter files in hidden directories by checking path that is relative to the base path.
64
- if (preg_match ('=/\.[^/]*/= ' , str_replace ($ this ->basePath , '' , $ path ))) {
87
+ if (preg_match ('=/\.[^/]*/= ' , str_replace (( string ) $ this ->basePath , '' , $ path ))) {
65
88
return false ;
66
89
}
67
90
@@ -84,6 +107,9 @@ private function acceptSuffix(string $filename): bool
84
107
return $ this ->acceptSubString ($ filename , $ this ->suffixes , self ::SUFFIX );
85
108
}
86
109
110
+ /**
111
+ * @psalm-param list<string> $subStrings
112
+ */
87
113
private function acceptSubString (string $ filename , array $ subStrings , int $ type ): bool
88
114
{
89
115
if (empty ($ subStrings )) {
0 commit comments