Conditions | 7 |
Paths | 6 |
Total Lines | 23 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 7 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
20 | 1 | public function lookup(string $path): Traversable |
|
21 | { |
||
22 | 1 | $real = realpath($path); |
|
23 | 1 | if (false === $real) { |
|
24 | 1 | return; |
|
25 | } |
||
26 | |||
27 | 1 | $len = mb_strlen($real . DIRECTORY_SEPARATOR); |
|
28 | 1 | foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($real)) as $file) { |
|
29 | /** @var SplFileInfo $file */ |
||
30 | 1 | $currentPath = mb_substr(strval($file), $len); |
|
31 | 1 | if ('..' == $file->getFilename()) { |
|
32 | // parent skip |
||
33 | 1 | } elseif ('.' == $file->getFilename()) { |
|
34 | // current process |
||
35 | 1 | $lastSlash = mb_strrpos($file->getRealPath(), DIRECTORY_SEPARATOR); |
|
36 | 1 | if (false === $lastSlash || '.' == $currentPath) { |
|
37 | 1 | yield ''; |
|
38 | } else { |
||
39 | 1 | yield DIRECTORY_SEPARATOR . mb_substr($file->getRealPath(), $len); |
|
40 | } |
||
41 | } else { |
||
42 | 1 | yield DIRECTORY_SEPARATOR . $currentPath; |
|
43 | } |
||
47 |