FileFinder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Borodulin\Finder;
6
7
class FileFinder implements FinderInterface
8
{
9
    /**
10
     * @var string[]
11
     */
12
    private $paths;
13
14
    /**
15
     * @var int
16
     */
17
    private $flags = \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::CURRENT_AS_FILEINFO;
18
19 1
    public function __construct(array $paths = [])
20
    {
21 1
        $this->paths = $paths;
22 1
    }
23
24 1
    public function addPath(string $path): FinderInterface
25
    {
26 1
        $this->paths[] = $path;
27
28 1
        return $this;
29
    }
30
31 1
    public function getIterator(): \Traversable
32
    {
33 1
        foreach ($this->paths as $path) {
34 1
            $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, $this->flags));
35
36
            /** @var \SplFileInfo $file */
37 1
            foreach ($iterator as $file) {
38 1
                if ($file->isDir()) {
39 1
                    continue;
40
                }
41 1
                if (false !== $file->getRealPath()) {
42 1
                    yield $file->getRealPath();
43
                }
44
            }
45
        }
46 1
    }
47
}
48