ReflectionClass   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 161
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 9

Test Coverage

Coverage 71.43%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 22
c 2
b 0
f 0
lcom 2
cbo 9
dl 0
loc 161
rs 10
ccs 35
cts 49
cp 0.7143

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getParent() 0 4 1
A getParentClass() 0 16 4
A setParent() 0 6 1
B isSubclassOf() 0 22 5
A isCloneable() 0 8 2
A isInstantiable() 0 8 2
A isInstance() 0 4 1
A isIterateable() 0 10 3
A newInstance() 0 4 1
A newInstanceArgs() 0 4 1
A newInstanceWithoutConstructor() 0 4 1
1
<?php
2
3
namespace Benoth\StaticReflection\Reflection;
4
5
class ReflectionClass extends ReflectionClassLike
6
{
7
    use Parts\AbstractTrait;
8
    use Parts\FinalTrait;
9
    use Parts\InterfaceTrait;
10
    use Parts\ConstantTrait;
11
    use Parts\PropertyTrait;
12
    use Parts\TraitUseTrait;
13
14
    protected $parent;
15
16 648
    public function getParent()
17
    {
18 648
        return $this->parent;
19
    }
20
21 630
    public function getParentClass()
22
    {
23 630
        if (!$this->getParent()) {
24 591
            return;
25
        }
26
27
        // Return internal objects Reflection
28 240
        if (class_exists($this->getParent(), false)) {
29 36
            $reflection = new \ReflectionClass($this->getParent());
30 36
            if ($reflection->isInternal()) {
31 36
                return $reflection;
32
            }
33
        }
34
35 204
        return $this->index->getClass($this->getParent());
36
    }
37
38 312
    public function setParent($parent)
39
    {
40 312
        $this->parent = $parent;
41
42 312
        return $this;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function isSubclassOf($className)
49
    {
50
        if (!is_string($className)) {
51
            return false;
52
        }
53
54
        $className = ltrim($className, '\\');
55
        if ($this->hasInterface($className)) {
56
            return true;
57
        }
58
59
        $parent = $this->getParentClass();
60
        while ($parent instanceof self) {
61
            if ($className === $parent->getName()) {
62
                return true;
63
            }
64
65
            $parent = $parent->getParentClass();
66
        }
67
68
        return false;
69
    }
70
71
    /**
72
     * Returns if the class is cloneable.
73
     *
74
     * @return bool
75
     */
76 15
    public function isCloneable()
77
    {
78 15
        if ($this->hasMethod('__clone')) {
79 3
            return $this->getMethod('__clone')->isPublic();
80
        }
81
82 12
        return true;
83
    }
84
85
    /**
86
     * Checks if the class is instantiable.
87
     *
88
     * @return bool
89
     */
90 15
    public function isInstantiable()
91
    {
92 15
        if ($this->hasMethod('__construct')) {
93 12
            return $this->getMethod('__construct')->isPublic();
94
        }
95
96 3
        return true;
97
    }
98
99
    /**
100
     * Checks if an object is an instance of the class.
101
     *
102
     * @param object $object
103
     *
104
     * @return bool
105
     */
106 3
    public function isInstance($object)
107
    {
108 3
        return get_class($object) === $this->getName();
109
    }
110
111
    /**
112
     * Checks if the class is iterateable.
113
     *
114
     * @return bool
115
     */
116 15
    public function isIterateable()
117
    {
118 15
        foreach ($this->getInterfaceNames() as $interfaceName) {
119 9
            if (trim($interfaceName, '\\') === 'Iterator') {
120 6
                return true;
121
            }
122 9
        }
123
124 9
        return false;
125
    }
126
127
    /**
128
     * Creates a new class instance from given arguments.
129
     *
130
     * @throws \ReflectionException Always... Can't be implemented.
131
     *
132
     * @return object
133
     */
134 15
    public function newInstance()
135
    {
136 15
        throw new \ReflectionException('StaticReflection can\'t create instances');
137
    }
138
139
    /**
140
     * Creates a new instance of the class, the given arguments are passed to the class constructor.
141
     *
142
     *
143
     * @param array $args The parameters to be passed to the class constructor as an array.
144
     *
145
     * @throws \ReflectionException Always... Can't be implemented.
146
     *
147
     * @return object
148
     */
149 15
    public function newInstanceArgs(array $args)
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
150
    {
151 15
        throw new \ReflectionException('StaticReflection can\'t create instances');
152
    }
153
154
    /**
155
     * Creates a new class instance without invoking the constructor.
156
     *
157
     * @throws \ReflectionException Always... Can't be implemented.
158
     *
159
     * @return object
160
     */
161 15
    public function newInstanceWithoutConstructor()
162
    {
163 15
        throw new \ReflectionException('StaticReflection can\'t create instances');
164
    }
165
}
166