Skip to content

Commit 30e8afd

Browse files
committed
Imporved simple location
1 parent f752d27 commit 30e8afd

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/Adapter/Simple/ClassScanner.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public function getClassNameFromFile($file)
4646
}
4747
}
4848

49-
if ($tokens[$i][0] === \T_CLASS) {
49+
$token = $tokens[$i][0];
50+
if ($token === \T_INTERFACE || $token === \T_CLASS || $token === \T_TRAIT) {
5051
for ($j = $i + 1; $j < count($tokens); $j++) {
5152
if ($tokens[$j][0] === \T_STRING) {
5253
$class = $tokens[$i + 2][1];

lib/Adapter/Simple/SimpleClassToFile.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use Phpactor\ClassFileConverter\Domain\FilePathCandidates;
77
use Phpactor\ClassFileConverter\Domain\ClassName;
88
use Phpactor\ClassFileConverter\Domain\FilePath;
9+
use RecursiveDirectoryIterator;
10+
use RecursiveIteratorIterator;
11+
use RegexIterator;
912

1013
class SimpleClassToFile implements ClassToFile
1114
{
@@ -29,15 +32,19 @@ public function classToFileCandidates(ClassName $className): FilePathCandidates
2932
{
3033
$candidates = [];
3134
$pattern = sprintf(
32-
'%s/**/%s.php',
33-
$this->cwd,
35+
'{^.*/%s.php$}',
3436
$className->name()
3537
);
36-
foreach (glob($pattern) as $phpFile) {
38+
39+
$iterator = new RecursiveDirectoryIterator($this->cwd);
40+
$iterator = new RecursiveIteratorIterator($iterator);
41+
$iterator = new RegexIterator($iterator, $pattern);
42+
43+
foreach ($iterator as $phpFile) {
3744
if (ClassName::fromString(
38-
$this->classScanner->getClassNameFromFile($phpFile)
45+
$this->classScanner->getClassNameFromFile($phpFile->getPathName())
3946
) == $className) {
40-
$candidates[] = FilePath::fromString($phpFile);
47+
$candidates[] = FilePath::fromString($phpFile->getPathName());
4148
}
4249
}
4350

0 commit comments

Comments
 (0)