@@ -86,11 +86,21 @@ final class FileFinder implements IteratorAggregate, Countable
86
86
/** @var array */
87
87
private array $ dirs = [];
88
88
89
- /** @var array */
89
+ /**
90
+ * File,dir name match.
91
+ *
92
+ * eg: '.php' '*.php' 'test.php'
93
+ *
94
+ * @var array
95
+ */
90
96
private array $ names = [];
91
97
92
98
/**
93
- * @var array exclude file/dir names
99
+ * File,dir name exclude
100
+ *
101
+ * eg: '.php' '*.php' 'test.php'
102
+ *
103
+ * @var array
94
104
*/
95
105
private array $ notNames = [];
96
106
@@ -516,7 +526,7 @@ public function isFollowLinks(): bool
516
526
}
517
527
518
528
/**
519
- * @param callable(\ SplFileInfo) $fn
529
+ * @param callable(SplFileInfo): void $fn
520
530
*/
521
531
public function each (callable $ fn ): void
522
532
{
@@ -529,8 +539,8 @@ public function each(callable $fn): void
529
539
* Retrieve an external iterator
530
540
*
531
541
* @link http://php.net/manual/en/iteratoraggregate.getiterator.php
532
- * @return Iterator|SplFileInfo[] An iterator
533
- * @throws LogicException
542
+ * @return Traversable An Traversable
543
+ * @psalm-return SplFileInfo[]
534
544
*/
535
545
public function getIterator (): Traversable
536
546
{
@@ -580,7 +590,7 @@ private function findInDirectory(string $dir): Iterator
580
590
private string $ subPath = '' ;
581
591
private bool |null $ rewindable = null ;
582
592
583
- private string $ directorySeparator = '/ ' ;
593
+ private string $ directorySep = '/ ' ;
584
594
private bool $ skipUnreadableDirs ;
585
595
586
596
public function __construct (string $ path , int $ flags , bool $ skipUnreadableDirs = true )
@@ -594,7 +604,7 @@ public function __construct(string $path, int $flags, bool $skipUnreadableDirs =
594
604
parent ::__construct ($ path , $ flags );
595
605
596
606
if ('/ ' !== DIRECTORY_SEPARATOR && !($ flags & self ::UNIX_PATHS )) {
597
- $ this ->directorySeparator = DIRECTORY_SEPARATOR ;
607
+ $ this ->directorySep = DIRECTORY_SEPARATOR ;
598
608
}
599
609
}
600
610
@@ -605,21 +615,21 @@ public function current(): SplFileInfo
605
615
}
606
616
607
617
if ('' !== $ subPathname ) {
608
- $ subPathname .= $ this ->directorySeparator ;
618
+ $ subPathname .= $ this ->directorySep ;
609
619
}
610
620
611
621
$ subPathname .= $ this ->getFilename ();
612
622
613
623
// $fileInfo = new \SplFileInfo($this->getPathname());
614
- $ fileInfo = new SplFileInfo ($ this ->rootPath . $ this ->directorySeparator . $ subPathname );
624
+ $ fileInfo = new SplFileInfo ($ this ->rootPath . $ this ->directorySep . $ subPathname );
615
625
// add props
616
626
$ fileInfo ->relativePath = $ this ->subPath ;
617
627
$ fileInfo ->relativePathname = $ subPathname ;
618
628
619
629
return $ fileInfo ;
620
630
}
621
631
622
- public function getChildren ()
632
+ public function getChildren (): RecursiveDirectoryIterator
623
633
{
624
634
try {
625
635
$ children = parent ::getChildren ();
@@ -693,9 +703,13 @@ public function hasChildren(): bool
693
703
return $ this ->iterator ->hasChildren ();
694
704
}
695
705
696
- public function getChildren (): RecursiveIterator | FilterIterator
706
+ public function getChildren (): ? RecursiveIterator
697
707
{
698
- $ children = new self ($ this ->iterator ->getChildren (), []);
708
+ if (!$ child = $ this ->iterator ->getChildren ()) {
709
+ return null ;
710
+ }
711
+
712
+ $ children = new self ($ child , []);
699
713
// sync
700
714
$ children ->excludes = $ this ->excludes ;
701
715
0 commit comments