ModuleDescriptor::__get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace TwoDojo\ModuleManager\Support;
4
5
class ModuleDescriptor implements \ArrayAccess
6
{
7
    protected $attributes = [];
8
9
    public function __construct(array $attributes = [])
10
    {
11
        foreach ($attributes as $key => $value) {
12
            $this->setAttribute($key, $value);
13
        }
14
    }
15
16
    public function hasAttribute($key)
17
    {
18
        return array_has($this->attributes, $key);
19
    }
20
21
    public function getAttribute($key, $default = null)
22
    {
23
        return array_get($this->attributes, $key, $default);
24
    }
25
26
    public function getAttributes()
27
    {
28
        return $this->attributes;
29
    }
30
31
    public function setAttribute($key, $value)
32
    {
33
        $this->attributes = array_set($this->attributes, $key, $value);
34
    }
35
36
    public function __set($key, $value)
37
    {
38
        $this->setAttribute($key, $value);
39
    }
40
41
    public function __get($name)
42
    {
43
        return $this->getAttribute($name);
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function offsetExists($offset)
50
    {
51
        return !is_null($this->getAttribute($offset));
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57
    public function offsetGet($offset)
58
    {
59
        return $this->getAttribute($offset);
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65
    public function offsetSet($offset, $value)
66
    {
67
        $this->setAttribute($offset, $value);
68
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73
    public function offsetUnset($offset)
74
    {
75
        unset($this->attributes[$offset]);
76
    }
77
}
78