GenericResource::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace CodeCloud\Bundle\ShopifyBundle\Api;
3
4
class GenericResource implements \ArrayAccess
5
{
6
7
    /**
8
     * @var array
9
     */
10
    private $data = array();
11
12
    /**
13
     * @param array $data
14
     */
15
    public function hydrate(array $data)
16
    {
17
        $this->data = $data;
18
    }
19
20
    /**
21
     * @param string $offset
22
     * @param mixed $value
23
     */
24
    public function offsetSet($offset, $value)
25
    {
26
        $this->data[$offset] = $value;
27
    }
28
29
    /**
30
     * @param string $offset
31
     * @return mixed
32
     */
33
    public function offsetGet($offset)
34
    {
35
        return $this->data[$offset];
36
    }
37
38
    /**
39
     * @param string $offset
40
     * @return bool
41
     */
42
    public function offsetExists($offset)
43
    {
44
        return array_key_exists($offset, $this->data);
45
    }
46
47
    /**
48
     * @param string $offset
49
     */
50
    public function offsetUnset($offset)
51
    {
52
        if ($this->offsetExists($offset)) {
53
            unset($this->data[$offset]);
54
        }
55
    }
56
57
    /**
58
     * @return array
59
     */
60
    public function toArray()
61
    {
62
        return $this->data;
63
    }
64
65
    /**
66
     * @param string $param
67
     * @param mixed $default
68
     * @return mixed
69
     */
70
    public function get($param, $default = null)
71
    {
72
        return $this->offsetExists($param) ? $this->offsetGet($param) : $default;
73
    }
74
75
    /**
76
     * @param array $data
77
     * @return GenericResource
78
     */
79
    public static function create(array $data = array())
80
    {
81
        $entity = new static();
82
        $entity->hydrate($data);
83
        return $entity;
84
    }
85
}
86