ReflectionProperty   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 109
rs 10
ccs 10
cts 20
cp 0.5

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefault() 0 4 1
A getDefaultType() 0 4 1
A getDefaultValue() 0 4 1
A setDefault() 0 7 1
A getValue() 0 8 2
A isDefault() 0 4 1
A setAccessible() 0 4 1
A setValue() 0 4 1
1
<?php
2
3
namespace Benoth\StaticReflection\Reflection;
4
5
class ReflectionProperty extends Reflection
6
{
7
    use Parts\VisibilityTrait;
8
    use Parts\StaticTrait;
9
    use Parts\DeclaringClassLikeTrait;
10
    use Parts\DocCommentTrait;
11
12
    protected $defaultType  = 'null';
13
    protected $defaultValue = null;
14
15
    /**
16
     * Gets the property's default type and value.
17
     *
18
     * @return array Type at index 0 and Value at index 1
19
     */
20 3
    public function getDefault()
21
    {
22 3
        return [$this->defaultType, $this->defaultValue];
23
    }
24
25
    /**
26
     * Gets the property's default type.
27
     *
28
     * @return string
29
     */
30 3
    public function getDefaultType()
31
    {
32 3
        return $this->defaultType;
33
    }
34
35
    /**
36
     * Gets the property's default value.
37
     *
38
     * @return mixed
39
     */
40 21
    public function getDefaultValue()
41
    {
42 21
        return $this->defaultValue;
43
    }
44
45
    /**
46
     * Sets the property's default value and type.
47
     *
48
     * @param string $type
49
     * @param mixed  $value
50
     */
51 786
    public function setDefault($type, $value)
52
    {
53 786
        $this->defaultType  = $type;
54 786
        $this->defaultValue = $value;
55
56 786
        return $this;
57
    }
58
59
    /**
60
     * Gets the property's value.
61
     *
62
     * @param object $object If the property is non-static an object must be provided to fetch the property from
63
     *
64
     * @throws \ReflectionException If something is received in parameter
65
     *
66
     * @return mixed
67
     */
68
    public function getValue($object = null)
69
    {
70
        if (!is_null($object)) {
71
            throw new \ReflectionException('StaticReflection can\'t fetch objects');
72
        }
73
74
        return $this->getDefaultValue();
75
    }
76
77
    /**
78
     * Checks whether the property was declared at compile-time or was dynamically declared at run-time.
79
     *
80
     * @return bool If the property was declared at compile-time
81
     */
82
    public function isDefault()
83
    {
84
        return true; // There's no instanciation with static reflection, so the property is always set at compile time
85
    }
86
87
    /**
88
     * Set property accessibility.
89
     *
90
     * @param bool $accessible
91
     *
92
     * @throws \ReflectionException Always... Can't be implemented
93
     *
94
     * @return bool
95
     */
96
    public function setAccessible($accessible)
0 ignored issues
show
Unused Code introduced by
The parameter $accessible 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...
97
    {
98
        throw new \ReflectionException('StaticReflection can\'t change property accessibility');
99
    }
100
101
    /**
102
     * Set property value.
103
     *
104
     * @param mixed $objectOrValue
105
     * @param mixed $value
106
     *
107
     * @throws \ReflectionException Always... Can't be implemented
108
     */
109
    public function setValue($objectOrValue, $value = null)
0 ignored issues
show
Unused Code introduced by
The parameter $objectOrValue 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...
Unused Code introduced by
The parameter $value 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...
110
    {
111
        throw new \ReflectionException('StaticReflection can\'t change a property value');
112
    }
113
}
114