DirectoryReflectorFactory::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Roave\BackwardCompatibility\Factory;
6
7
use Roave\BetterReflection\Reflector\ClassReflector;
8
use Roave\BetterReflection\SourceLocator\Ast\Locator;
9
use Roave\BetterReflection\SourceLocator\Exception\InvalidDirectory;
10
use Roave\BetterReflection\SourceLocator\Exception\InvalidFileInfo;
11
use Roave\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
12
use Roave\BetterReflection\SourceLocator\Type\DirectoriesSourceLocator;
13
use Roave\BetterReflection\SourceLocator\Type\MemoizingSourceLocator;
14
use Roave\BetterReflection\SourceLocator\Type\SourceLocator;
15
16
/**
17
 * @deprecated this class builds a simplistic reflector with a DirectoriesSourceLocator around a given
18
 *             path: that is no longer the preferred approach.
19
 *             Please use {@see \Roave\BackwardCompatibilityCheck\Factory\ComposerInstallationReflectorFactory} instead.
20
 *
21
 * @codeCoverageIgnore
22
 */
23
final class DirectoryReflectorFactory
24
{
25
    /** @var Locator */
26
    private $astLocator;
27
28
    public function __construct(Locator $astLocator)
29
    {
30
        $this->astLocator = $astLocator;
31
    }
32
33
    /**
34
     * @throws InvalidFileInfo
35
     * @throws InvalidDirectory
36
     */
37
    public function __invoke(
38
        string $directory,
39
        SourceLocator $dependencies
40
    ) : ClassReflector {
41
        return new ClassReflector(
42
            new MemoizingSourceLocator(new AggregateSourceLocator([
43
                new DirectoriesSourceLocator([$directory], $this->astLocator),
44
                $dependencies,
45
            ]))
46
        );
47
    }
48
}
49