ModuleDescriptor   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 12
dl 0
loc 71
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 3 1
A __set() 0 3 1
A __construct() 0 4 2
A hasAttribute() 0 3 1
A getAttribute() 0 3 1
A offsetExists() 0 3 1
A offsetGet() 0 3 1
A offsetSet() 0 3 1
A setAttribute() 0 3 1
A offsetUnset() 0 3 1
A getAttributes() 0 3 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