MagicMapTrait::rewind()   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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Swaggest\JsonSchema;
4
5
trait MagicMapTrait
6
{
7
    protected $__arrayOfData = array();
8
9
    /**
10
     * @param string $name
11
     * @param mixed $column
12
     * @return static
13
     */
14 1129
    public function __set($name, $column)
15
    {
16 1129
        $this->__arrayOfData[$name] = $column;
17 1129
        return $this;
18
    }
19
20 216
    public function &__get($name)
21
    {
22 216
        if (isset($this->__arrayOfData[$name])) {
23 132
            return $this->__arrayOfData[$name];
24
        } else {
25 94
            $tmp = null;
26 94
            return $tmp;
27
        }
28
    }
29
30
    public function offsetExists($offset)
31
    {
32
        return array_key_exists($offset, $this->__arrayOfData);
33
    }
34
35 455
    public function &offsetGet($offset)
36
    {
37 455
        if (isset($this->__arrayOfData[$offset])) {
38 20
            return $this->__arrayOfData[$offset];
39
        } else {
40 439
            $tmp = null;
41 439
            return $tmp;
42
        }
43
    }
44
45
    public function offsetSet($offset, $value)
46
    {
47
        $this->__set($offset, $value);
48
    }
49
50
    public function offsetUnset($offset)
51
    {
52
        unset($this->__arrayOfData[$offset]);
53
    }
54
55 591
    public function &toArray()
56
    {
57 591
        return $this->__arrayOfData;
58
    }
59
60
    public function jsonSerialize()
61
    {
62
        return (object)$this->__arrayOfData;
63
    }
64
65
66
    /** @var \ArrayIterator */
67
    private $iterator;
68
    /**
69
     * Return the current element
70
     * @link http://php.net/manual/en/iterator.current.php
71
     * @return mixed Can return any type.
72
     * @since 5.0.0
73
     */
74 178
    public function current()
75
    {
76 178
        return $this->iterator->current();
77
    }
78
79
    /**
80
     * Move forward to next element
81
     * @link http://php.net/manual/en/iterator.next.php
82
     * @return void Any returned value is ignored.
83
     * @since 5.0.0
84
     */
85 156
    public function next()
86
    {
87 156
        $this->iterator->next();
88 156
    }
89
90
    /**
91
     * Return the key of the current element
92
     * @link http://php.net/manual/en/iterator.key.php
93
     * @return mixed scalar on success, or null on failure.
94
     * @since 5.0.0
95
     */
96 178
    public function key()
97
    {
98 178
        return $this->iterator->key();
99
    }
100
101
    /**
102
     * Checks if current position is valid
103
     * @link http://php.net/manual/en/iterator.valid.php
104
     * @return boolean The return value will be casted to boolean and then evaluated.
105
     * Returns true on success or false on failure.
106
     * @since 5.0.0
107
     */
108 178
    public function valid()
109
    {
110 178
        return $this->iterator->valid();
111
    }
112
113
    /**
114
     * Rewind the Iterator to the first element
115
     * @link http://php.net/manual/en/iterator.rewind.php
116
     * @return void Any returned value is ignored.
117
     * @since 5.0.0
118
     */
119 178
    public function rewind()
120
    {
121 178
        $this->iterator = new \ArrayIterator($this->__arrayOfData);
122 178
    }
123
124
125 1131
    public function __isset($name)
126
    {
127 1131
        if (isset($this->__arrayOfData[$name])) {
128 154
            return true;
129
        } else {
130 1131
            return isset($this->$name);
131
        }
132
    }
133
}
134