@@ -86,11 +86,21 @@ final class FileFinder implements IteratorAggregate, Countable
8686 /** @var array */
8787 private array $ dirs = [];
8888
89- /** @var array */
89+ /**
90+ * File,dir name match.
91+ *
92+ * eg: '.php' '*.php' 'test.php'
93+ *
94+ * @var array
95+ */
9096 private array $ names = [];
9197
9298 /**
93- * @var array exclude file/dir names
99+ * File,dir name exclude
100+ *
101+ * eg: '.php' '*.php' 'test.php'
102+ *
103+ * @var array
94104 */
95105 private array $ notNames = [];
96106
@@ -516,7 +526,7 @@ public function isFollowLinks(): bool
516526 }
517527
518528 /**
519- * @param callable(\ SplFileInfo) $fn
529+ * @param callable(SplFileInfo): void $fn
520530 */
521531 public function each (callable $ fn ): void
522532 {
@@ -529,8 +539,8 @@ public function each(callable $fn): void
529539 * Retrieve an external iterator
530540 *
531541 * @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[]
534544 */
535545 public function getIterator (): Traversable
536546 {
@@ -580,7 +590,7 @@ private function findInDirectory(string $dir): Iterator
580590 private string $ subPath = '' ;
581591 private bool |null $ rewindable = null ;
582592
583- private string $ directorySeparator = '/ ' ;
593+ private string $ directorySep = '/ ' ;
584594 private bool $ skipUnreadableDirs ;
585595
586596 public function __construct (string $ path , int $ flags , bool $ skipUnreadableDirs = true )
@@ -594,7 +604,7 @@ public function __construct(string $path, int $flags, bool $skipUnreadableDirs =
594604 parent ::__construct ($ path , $ flags );
595605
596606 if ('/ ' !== DIRECTORY_SEPARATOR && !($ flags & self ::UNIX_PATHS )) {
597- $ this ->directorySeparator = DIRECTORY_SEPARATOR ;
607+ $ this ->directorySep = DIRECTORY_SEPARATOR ;
598608 }
599609 }
600610
@@ -605,21 +615,21 @@ public function current(): SplFileInfo
605615 }
606616
607617 if ('' !== $ subPathname ) {
608- $ subPathname .= $ this ->directorySeparator ;
618+ $ subPathname .= $ this ->directorySep ;
609619 }
610620
611621 $ subPathname .= $ this ->getFilename ();
612622
613623 // $fileInfo = new \SplFileInfo($this->getPathname());
614- $ fileInfo = new SplFileInfo ($ this ->rootPath . $ this ->directorySeparator . $ subPathname );
624+ $ fileInfo = new SplFileInfo ($ this ->rootPath . $ this ->directorySep . $ subPathname );
615625 // add props
616626 $ fileInfo ->relativePath = $ this ->subPath ;
617627 $ fileInfo ->relativePathname = $ subPathname ;
618628
619629 return $ fileInfo ;
620630 }
621631
622- public function getChildren ()
632+ public function getChildren (): RecursiveDirectoryIterator
623633 {
624634 try {
625635 $ children = parent ::getChildren ();
@@ -693,9 +703,13 @@ public function hasChildren(): bool
693703 return $ this ->iterator ->hasChildren ();
694704 }
695705
696- public function getChildren (): RecursiveIterator | FilterIterator
706+ public function getChildren (): ? RecursiveIterator
697707 {
698- $ children = new self ($ this ->iterator ->getChildren (), []);
708+ if (!$ child = $ this ->iterator ->getChildren ()) {
709+ return null ;
710+ }
711+
712+ $ children = new self ($ child , []);
699713 // sync
700714 $ children ->excludes = $ this ->excludes ;
701715
0 commit comments