GenericResource   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 80
rs 10
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 2
A toArray() 0 3 1
A offsetUnset() 0 4 2
A offsetExists() 0 3 1
A offsetGet() 0 3 1
A offsetSet() 0 3 1
A create() 0 5 1
A hydrate() 0 3 1
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