Completed
Push — master ( 44b412...e96d03 )
by Andrey
02:04
created

InstanceFinder::__construct()   A

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
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Borodulin\Container\Autowire;
6
7
class InstanceFinder
8
{
9
    /**
10
     * @var array
11
     */
12
    private $classNames;
13
14 13
    public function __construct(array $classNames)
15
    {
16 13
        $this->classNames = $classNames;
17 13
    }
18
19 1
    public function findInstanceOf($interface): \Traversable
20
    {
21 1
        foreach ($this->classNames as $className) {
22 1
            if (class_exists($className)) {
23 1
                $reflection = new \ReflectionClass($className);
24 1
                if ($reflection->implementsInterface($interface) || $reflection->isSubclassOf($interface)) {
25 1
                    yield $className;
26
                }
27
            }
28
        }
29 1
    }
30
}
31