RecursiveFileReader   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 9
c 1
b 0
f 0
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A read() 0 11 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Component\Catalog\Manage\Update;
6
7
use Generator;
8
9
/**
10
 * Recursively iterate over all files in the directory and yield the absolute path of every file
11
 */
12
final class RecursiveFileReader implements RecursiveFileReaderInterface
13
{
14
    /**
15
     * @return Generator<string> Absolute path to the file
16
     */
17 2
    public function read(string $directory): Generator
18
    {
19 2
        $files = @scandir($directory);
20
21 2
        if ($files !== false) {
22 1
            foreach ($files as $value) {
23 1
                $path = (string) realpath($directory . DIRECTORY_SEPARATOR . $value);
24 1
                if (!is_dir($path)) {
25 1
                    yield $path;
26 1
                } elseif ($value !== '.' && $value !== '..') {
27 1
                    yield from $this->read($path);
28
                }
29
            }
30
        }
31
    }
32
}
33