@@ -534,21 +534,23 @@ public function getIterator(): \Iterator {
534534 public function getElements (): array {
535535 $ classes = [];
536536 $ subdirs = [];
537- foreach ($ this ->scanThisDir ( ) as $ candidate ) {
538- if (!preg_match ( self :: CANDIDATE_REGEX , $ candidate , $ m ) ) {
539- continue ;
540- }
541- [, $ name , $ ext ] = $ m ;
542- $ path = $ this ->directory . '/ ' . $ candidate ;
543- if ( $ ext ) {
544- if (is_file ( $ path )) {
545- $ classes [ $ path ] = $ this -> terminatedNamespace . $ name ;
537+ foreach (NsDirUtil:: getDirContents ( $ this ->directory ) as $ candidate => $ is_dir ) {
538+ if (!$ is_dir ) {
539+ if (! \str_ends_with ( $ candidate , ' .php ' )) {
540+ continue ;
541+ }
542+ $ path = $ this ->directory . '/ ' . $ candidate ;
543+ $ name = \substr ( $ candidate , 0 , - 4 );
544+ if (! \preg_match ( self :: CLASS_NAME_REGEX , $ name )) {
545+ continue ;
546546 }
547+ $ classes [$ path ] = $ this ->terminatedNamespace . $ name ;
547548 }
548549 else {
549- if (is_dir ( $ path )) {
550- $ subdirs [ $ candidate ] = $ this -> subdir ( $ candidate ) ;
550+ if (! \preg_match ( self :: CLASS_NAME_REGEX , $ candidate )) {
551+ continue ;
551552 }
553+ $ subdirs [$ candidate ] = $ this ->subdir ($ candidate );
552554 }
553555 }
554556 /** @var array<string, class-string> $classes */
@@ -560,16 +562,11 @@ public function getElements(): array {
560562 */
561563 public function getClassFilesHere (): array {
562564 $ classFiles = [];
563- foreach ($ this ->scanThisDir () as $ candidate ) {
564- if ('. ' === $ candidate [0 ]
565- || !\str_ends_with ($ candidate , '.php ' )
566- ) {
565+ foreach (NsDirUtil::getDirContents ($ this ->directory ) as $ candidate => $ is_dir ) {
566+ if ($ is_dir || !\str_ends_with ($ candidate , '.php ' )) {
567567 continue ;
568568 }
569569 $ path = $ this ->directory . '/ ' . $ candidate ;
570- if (!\is_file ($ path )) {
571- continue ;
572- }
573570 $ name = \substr ($ candidate , 0 , -4 );
574571 if (!\preg_match (self ::CLASS_NAME_REGEX , $ name )) {
575572 continue ;
@@ -584,31 +581,12 @@ public function getClassFilesHere(): array {
584581 * @return \Iterator<string, static>
585582 */
586583 public function getSubdirsHere (): \Iterator {
587- foreach ($ this ->scanThisDir () as $ candidate ) {
588- if (!preg_match (self ::CLASS_NAME_REGEX , $ candidate )) {
589- continue ;
590- }
591- $ path = $ this ->directory . '/ ' . $ candidate ;
592- if (!\is_dir ($ path )) {
584+ foreach (NsDirUtil::getDirContents ($ this ->directory ) as $ candidate => $ is_dir ) {
585+ if (!$ is_dir || !preg_match (self ::CLASS_NAME_REGEX , $ candidate )) {
593586 continue ;
594587 }
595588 yield $ candidate => $ this ->subdir ($ candidate );
596589 }
597590 }
598591
599- /**
600- * Runs scandir() on this namespace directory.
601- *
602- * Throws a runtime exception on failure, instead of returning false.
603- * This is considered an unhandled exception, because it is assumed that the
604- * current directory always exists.
605- *
606- * @return list<string>
607- * Items in the directory in alphabetic order.
608- * This also includes '.' and '..'.
609- */
610- private function scanThisDir (): array {
611- return NsDirUtil::scanKnownDir ($ this ->directory );
612- }
613-
614592}
0 commit comments