Completed
Pull Request — master (#13)
by Viacheslav
03:57
created

MagicMapTrait::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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