Iterator::asArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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