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

InstanceFinder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

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