RecursiveFileReader::read()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 11
ccs 9
cts 9
cp 1
rs 9.2222
cc 6
nc 5
nop 1
crap 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