ClassFinder   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 3
A addPath() 0 5 1
A getIterator() 0 10 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Borodulin\Finder;
6
7
use Borodulin\Finder\Exception\ParseException;
8
9
class ClassFinder implements FinderInterface
10
{
11
    /**
12
     * @var FinderInterface
13
     */
14
    private $fileFinder;
15
    /**
16
     * @var callable|null
17
     */
18
    private $classExtractor;
19
20 1
    public function __construct(FinderInterface $fileFinder = null, callable $classExtractor = null)
21
    {
22 1
        $this->fileFinder = $fileFinder ?: new FileFinder();
23 1
        $this->classExtractor = $classExtractor ?: new ClassExtractor();
24 1
    }
25
26 1
    public function addPath(string $path): FinderInterface
27
    {
28 1
        $this->fileFinder->addPath($path);
29
30 1
        return $this;
31
    }
32
33 1
    public function getIterator(): \Traversable
34
    {
35 1
        foreach ($this->fileFinder as $fileName) {
36 1
            if ('.php' === substr($fileName, -4)) {
37
                try {
38 1
                    $class = \call_user_func($this->classExtractor, $fileName);
39 1
                    if ($class) {
40 1
                        yield $class;
41
                    }
42 1
                } catch (ParseException $exception) {
43
                    // skip files with parse error
44
                }
45
            }
46
        }
47 1
    }
48
}
49