Completed
Pull Request — master (#82)
by Loren
03:39
created

ReflectionExtension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 2
dl 0
loc 57
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A wasIncluded() 0 4 1
A getClasses() 0 11 3
A getFunctions() 0 11 3
1
<?php
2
/**
3
 * Parser Reflection API
4
 *
5
 * @copyright Copyright 2015, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Go\ParserReflection;
12
13
use ReflectionExtension as BaseReflectionExtension;
14
15
/**
16
 * Returns AST-based reflections from extensions.
17
 */
18
class ReflectionExtension extends BaseReflectionExtension implements ReflectionInterface
19
{
20
    /**
21
     * @var null|ReflectionClass[] ParsedReflection wrapped classes.
22
     */
23
    private $classes;
24
25
    /**
26
     * @var null|ReflectionFunction[] ParsedReflection wrapped functions.
27
     */
28
    private $functions;
29
30
    /**
31
     * Has extension been loaded by PHP.
32
     *
33
     * @return true
34
     *     Enabled extensions are always loaded.
35
     */
36
    public function wasIncluded()
37
    {
38
        return true;
39
    }
40
41
    /**
42
     * Returns list of reflection classes
43
     *
44
     * @return \ReflectionClass[]
45
     */
46 2
    public function getClasses()
47
    {
48 2
        if (!isset($this->classes)) {
49 2
            $this->classes = [];
50 2
            foreach (parent::getClasses() as $index => $classReflection) {
51 2
                $this->classes[$index] = new ReflectionClass($classReflection->name);
52
            }
53
        }
54
55 2
        return $this->classes;
56
    }
57
58
    /**
59
     * Returns list of reflection functions
60
     *
61
     * @return \ReflectionFunction[]
62
     */
63 2
    public function getFunctions()
64
    {
65 2
        if (!isset($this->functions)) {
66 2
            $this->functions = [];
67 2
            foreach (parent::getFunctions() as $index => $functionReflection) {
68 2
                $this->functions[$index] = new ReflectionFunction($functionReflection->name);
69
            }
70
        }
71
72 2
        return $this->functions;
73
    }
74
}
75