Iterator   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 1
Metric Value
eloc 18
c 6
b 0
f 1
dl 0
loc 114
ccs 21
cts 21
cp 1
rs 10
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __unset() 0 3 1
A atData() 0 3 1
A asArray() 0 3 1
A __get() 0 3 1
A export() 0 3 1
A __isset() 0 3 1
A __toString() 0 3 1
A __debugInfo() 0 3 1
A __set() 0 3 1
A __sleep() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace Bavix\Iterator;
4
5
use Bavix\Helpers\JSON;
6
7
class Iterator implements \Countable, \Iterator, \Serializable, \ArrayAccess, \JsonSerializable
8
{
9
10
    use Traits\Countable;
11
    use Traits\Iterator;
12
    use Traits\Serializable;
13
    use Traits\ArrayAccess;
14
    use Traits\JsonSerializable;
15
16
    /**
17
     * @var array
18
     */
19
    protected $data;
20
21
    /**
22
     * Iterator constructor.
23
     *
24
     * @param array $data
25
     */
26 9
    public function __construct(array $data = [])
27
    {
28 9
        $this->data = $data;
29 9
    }
30
31
    /**
32
     * @return array
33
     */
34 2
    public function asArray()
35
    {
36 2
        return $this->jsonSerialize();
37
    }
38
39
    /**
40
     * @param string $offset
41
     * @param mixed  $default
42
     *
43
     * @return mixed
44
     */
45 1
    public function atData($offset, $default = null)
46
    {
47 1
        return $this->data[$offset] ?? $default;
48
    }
49
50
    /**
51
     * @return string
52
     */
53 1
    public function export()
54
    {
55 1
        return var_export($this->data, true);
56
    }
57
58
    /**
59
     * @param string $offset
60
     *
61
     * @return array|mixed
62
     */
63 1
    public function __get($offset)
64
    {
65 1
        return $this->offsetGet($offset);
66
    }
67
68
    /**
69
     * @param string $offset
70
     * @param mixed  $value
71
     */
72 1
    public function __set($offset, $value)
73
    {
74 1
        $this->offsetSet($offset, $value);
75 1
    }
76
77
    /**
78
     * @param string $offset
79
     *
80
     * @return bool
81
     */
82 1
    public function __isset($offset)
83
    {
84 1
        return $this->offsetExists($offset);
85
    }
86
87
    /**
88
     * @param string $offset
89
     */
90 1
    public function __unset($offset)
91
    {
92 1
        $this->offsetUnset($offset);
93 1
    }
94
95
    /**
96
     * @return array
97
     *
98
     * @codeCoverageIgnore
99
     */
100
    public function __sleep()
101
    {
102
        return ['data'];
103
    }
104
105
    /**
106
     * @return string
107
     */
108 1
    public function __toString()
109
    {
110 1
        return JSON::encode($this->data);
111
    }
112
113
    /**
114
     * @return array
115
     *
116
     * @codeCoverageIgnore
117
     */
118
    public function __debugInfo()
119
    {
120
        return $this->data;
121
    }
122
123
}
124