ArrayAccessible   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 130
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 1

10 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A has() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
A __get() 0 4 1
A __set() 0 4 1
A __isset() 0 4 1
A __unset() 0 4 1
1
<?php
2
3
4
namespace SmartWeb\ModuleTesting\Support;
5
6
use SmartWeb\ModuleTesting\Support\Concerns;
7
8
9
/**
10
 * Trait ArrayAccessible
11
 *
12
 * @package SmartWeb\ModuleTesting\Support
13
 */
14
trait ArrayAccessible
15
{
16
    
17
    use Concerns\HasAttributes;
18
    
19
    /**
20
     * Get an attribute from the container.
21
     *
22
     * @param string $key
23
     * @param mixed  $default
24
     *
25
     * @return mixed
26
     */
27
    public function get(string $key, $default = null)
28
    {
29
        if ($this->has($key)) {
30
            return $this->attributes[$key];
31
        }
32
        
33
        return $default;
34
    }
35
    
36
    /**
37
     * @param string $key
38
     *
39
     * @return bool
40
     */
41
    public function has(string $key) : bool
42
    {
43
        return array_key_exists($key, $this->attributes);
44
    }
45
    
46
    /**
47
     * Determine if the given offset exists.
48
     *
49
     * @param  string $offset
50
     *
51
     * @return bool
52
     */
53
    public function offsetExists($offset)
54
    {
55
        return isset($this->{$offset});
56
    }
57
    
58
    /**
59
     * Get the value for a given offset.
60
     *
61
     * @param  string $offset
62
     *
63
     * @return mixed
64
     */
65
    public function offsetGet($offset)
66
    {
67
        return $this->{$offset};
68
    }
69
    
70
    /**
71
     * Set the value at the given offset.
72
     *
73
     * @param  string $offset
74
     * @param  mixed  $value
75
     *
76
     * @return void
77
     */
78
    public function offsetSet($offset, $value)
79
    {
80
        $this->{$offset} = $value;
81
    }
82
    
83
    /**
84
     * Unset the value at the given offset.
85
     *
86
     * @param  string $offset
87
     *
88
     * @return void
89
     */
90
    public function offsetUnset($offset)
91
    {
92
        unset($this->{$offset});
93
    }
94
    
95
    /**
96
     * Dynamically retrieve the value of an attribute.
97
     *
98
     * @param  string $key
99
     *
100
     * @return mixed
101
     */
102
    public function __get($key)
103
    {
104
        return $this->get($key);
105
    }
106
    
107
    /**
108
     * Dynamically set the value of an attribute.
109
     *
110
     * @param  string $key
111
     * @param  mixed  $value
112
     *
113
     * @return void
114
     */
115
    public function __set($key, $value)
116
    {
117
        $this->attributes[$key] = $value;
118
    }
119
    
120
    /**
121
     * Dynamically check if an attribute is set.
122
     *
123
     * @param  string $key
124
     *
125
     * @return bool
126
     */
127
    public function __isset($key)
128
    {
129
        return isset($this->attributes[$key]);
130
    }
131
    
132
    /**
133
     * Dynamically unset an attribute.
134
     *
135
     * @param  string $key
136
     *
137
     * @return void
138
     */
139
    public function __unset($key)
140
    {
141
        unset($this->attributes[$key]);
142
    }
143
}
144