Passed
Pull Request — master (#38)
by Viacheslav
02:49
created

MagicMapTrait::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 2
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 1094
    public function __set($name, $column)
15
    {
16 1094
        $this->__arrayOfData[$name] = $column;
17 1094
        return $this;
18
    }
19
20 207
    public function &__get($name)
21
    {
22 207
        if (isset($this->__arrayOfData[$name])) {
23 126
            return $this->__arrayOfData[$name];
24
        } else {
25 89
            $tmp = null;
26 89
            return $tmp;
27
        }
28
    }
29
30
    public function offsetExists($offset)
31
    {
32
        return array_key_exists($offset, $this->__arrayOfData);
33
    }
34
35 435
    public function &offsetGet($offset)
36
    {
37 435
        if (isset($this->__arrayOfData[$offset])) {
38 434
            return $this->__arrayOfData[$offset];
39
        } else {
40 419
            $tmp = null;
41 419
            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 3137
    public function &toArray()
56
    {
57 3137
        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 166
    public function current()
75
    {
76 166
        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 144
    public function next()
86
    {
87 144
        $this->iterator->next();
88 144
    }
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 166
    public function key()
97
    {
98 166
        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 166
    public function valid()
109
    {
110 166
        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 166
    public function rewind()
120
    {
121 166
        $this->iterator = new \ArrayIterator($this->__arrayOfData);
122 166
    }
123
124
125 1100
    public function __isset($name)
126
    {
127 1100
        if (isset($this->__arrayOfData[$name])) {
128 152
            return true;
129
        } else {
130 1100
            return isset($this->$name);
131
        }
132
    }
133
}