Completed
Push — master ( c2be97...312fc5 )
by Stephen
02:08
created

Store::offsetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
namespace StarCitizen\Models;
3
4
use ArrayAccess;
5
use Countable;
6
use IteratorAggregate;
7
use ArrayIterator;
8
9
/**
10
 * Class Store
11
 *
12
 * @package StarCitizen\Models;
13
 */
14
class Store implements ArrayAccess, Countable, IteratorAggregate
15
{
16
    protected $items = [];
17
18
    /**
19
     * @return ArrayIterator
20
     */
21
    public function getIterator()
22
    {
23
        return new ArrayIterator($this->items);
24
    }
25
26
    /**
27
     * @param mixed $offset
28
     *
29
     * @return bool
30
     */
31
    public function offsetExists($offset)
32
    {
33
        if (array_key_exists($offset, $this->items))
34
            return true;
35
36
        return false;
37
    }
38
39
    /**
40
     * @param mixed $offset
41
     *
42
     * @return bool|mixed
43
     */
44
    public function offsetGet($offset)
45
    {
46
        if ($this->offsetExists($offset))
47
            return $this->items[$offset];
48
49
        return false;
50
    }
51
52
    /**
53
     * @param mixed $offset
54
     * @param mixed $value
55
     */
56
    public function offsetSet($offset, $value)
57
    {
58
        $this->items[$offset] = $value;
59
    }
60
61
    /**
62
     * @param mixed $offset
63
     */
64
    public function offsetUnset($offset)
65
    {
66
        if ($this->offsetExists($offset) && isset($this->items[$offset]))
67
            unset ($this->items[$offset]);
68
    }
69
70
    /**
71
     * @return int
72
     */
73
    public function count()
74
    {
75
        return count($this->items);
76
    }
77
78
    /**
79
     * @param $name
80
     *
81
     * @return bool|mixed
82
     */
83
    public function __get($name)
84
    {
85
        return $this->offsetGet($name);
86
    }
87
88
    /**
89
     * @param $name
90
     * @param $value
91
     */
92
    public function __set($name, $value)
93
    {
94
        $this->offsetSet($name, $value);
95
    }
96
}