Skip to content

Commit 489fc5c

Browse files
committed
Use NsDirUtil static methods in ClassFilesIA_NamespaceDirectoryPsr4.
1 parent 60272cb commit 489fc5c

File tree

1 file changed

+1
-47
lines changed

1 file changed

+1
-47
lines changed

src/ClassFilesIA/ClassFilesIA_NamespaceDirectoryPsr4.php

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77

88
class ClassFilesIA_NamespaceDirectoryPsr4 implements ClassFilesIAInterface {
99

10-
/**
11-
* See http://php.net/manual/en/language.oop5.basic.php
12-
*/
13-
const CLASS_NAME_REGEX = /** @lang RegExp */ '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/';
14-
1510
/**
1611
* @param string $dir
1712
* @param string $namespace
@@ -78,48 +73,7 @@ public function withRealpathRoot(): static {
7873
* {@inheritdoc}
7974
*/
8075
public function getIterator(): \Iterator {
81-
return self::scan($this->directory, $this->terminatedNamespace);
76+
return NsDirUtil::iterate($this->directory, $this->terminatedNamespace);
8277
}
8378

84-
/**
85-
* @param string $dir
86-
* @param string $terminatedNamespace
87-
*
88-
* @return \Iterator<string, class-string>
89-
* Format: $[$file] = $class
90-
*/
91-
private static function scan(string $dir, string $terminatedNamespace): \Iterator {
92-
$candidates = @\scandir($dir, \SCANDIR_SORT_ASCENDING);
93-
if ($candidates === false) {
94-
throw new \RuntimeException("Failed to scandir('$dir').");
95-
}
96-
foreach ($candidates as $candidate) {
97-
if ('.' === $candidate[0]) {
98-
continue;
99-
}
100-
$path = $dir . '/' . $candidate;
101-
if (str_ends_with($candidate, '.php')) {
102-
if (!is_file($path)) {
103-
continue;
104-
}
105-
$name = substr($candidate, 0, -4);
106-
if (!preg_match(self::CLASS_NAME_REGEX, $name)) {
107-
continue;
108-
}
109-
// The value is a class-string, but PhpStan does not know.
110-
// @phpstan-ignore generator.valueType
111-
yield $path => $terminatedNamespace . $name;
112-
}
113-
else {
114-
if (!is_dir($path)) {
115-
continue;
116-
}
117-
if (!preg_match(self::CLASS_NAME_REGEX, $candidate)) {
118-
continue;
119-
}
120-
// @todo Make PHP 7 version with "yield from".
121-
yield from self::scan($path, $terminatedNamespace . $candidate . '\\');
122-
}
123-
}
124-
}
12579
}

0 commit comments

Comments
 (0)