Test Failed
Pull Request — master (#26)
by Jan-Marten
05:00
created

ReflectionTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getReflectionEnvironment() 0 7 2
A getClassReflection() 0 5 1
1
<?php
2
/**
3
 * Copyright MediaCT. All rights reserved.
4
 * https://www.mediact.nl
5
 */
6
7
namespace Mediact\DependencyGuard\Reflection;
8
9
use Roave\BetterReflection\BetterReflection;
10
use Roave\BetterReflection\Reflection\ReflectionClass;
11
12
trait ReflectionTrait
13
{
14
    /** @var BetterReflection */
15
    private static $reflectionEnvironment;
16
17
    /**
18
     * Get the current reflection environment.
19
     *
20
     * @return BetterReflection
21
     */
22
    private static function getReflectionEnvironment(): BetterReflection
23
    {
24
        if (self::$reflectionEnvironment === null) {
25
            self::$reflectionEnvironment = new BetterReflection();
26
        }
27
28
        return self::$reflectionEnvironment;
29
    }
30
31
    /**
32
     * Get the reflection for the given class name.
33
     *
34
     * @param string $className
35
     *
36
     * @return ReflectionClass
37
     */
38
    public function getClassReflection(string $className): ReflectionClass
39
    {
40
        return static::getReflectionEnvironment()
41
            ->classReflector()
42
            ->reflect($className);
43
    }
44
}
45