Completed
Push — master ( aedaa6...d154ad )
by Valentin
06:14
created

Locator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Cycle\ORM\Promise\Materizalizer\ClassLocator;
5
6
use Spiral\Tokenizer\ClassesInterface;
7
use Spiral\Tokenizer\ClassLocator;
8
9
class Locator implements ClassesInterface
10
{
11
    /** @var ClassLocator */
12
    private $locator;
13
14
    public function __construct(ClassLocator $locator)
15
    {
16
        $this->locator = $locator;
17
    }
18
19
    /**
20
     * {@inheritdoc}
21
     * @param string|null $interfaceToBeImplemented Additional check for targets to check interface implementation.
22
     *
23
     * @return \ReflectionClass[]
24
     */
25
    public function getClasses($target = null, string $interfaceToBeImplemented = null): array
26
    {
27
        /** @var \ReflectionClass[] $targets */
28
        $targets = $this->locator->getClasses($target);
29
        if (!empty($interfaceToBeImplemented)) {
30
            foreach ($targets as $name => $reflection) {
31
                if (!$reflection->implementsInterface($interfaceToBeImplemented)) {
32
                    unset($targets[$name]);
33
                }
34
            }
35
        }
36
37
        return $targets;
38
    }
39
}