FileFinder   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 13
c 1
b 0
f 0
dl 0
loc 36
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addPath() 0 5 1
A getIterator() 0 12 5
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