Completed
Push — d64 ( b460e4...2ffd1a )
by Welling
03:33
created

Entry::getMetaData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Directus – <http://getdirectus.com>
5
 *
6
 * @link      The canonical repository – <https://github.com/directus/directus>
7
 * @copyright Copyright 2006-2016 RANGER Studio, LLC – <http://rangerstudio.com>
8
 * @license   GNU General Public License (v3) – <http://www.gnu.org/copyleft/gpl.html>
9
 */
10
11
namespace Directus\SDK\Response;
12
13
/**
14
 * Entry
15
 *
16
 * @author Welling Guzmán <[email protected]>
17
 */
18
class Entry implements ResponseInterface, \ArrayAccess
19
{
20
    /**
21
     * @var array
22
     */
23
    protected $data = null;
24
25
    /**
26
     * @var array
27
     */
28
    protected $metadata = null;
29
30
    /**
31
     * Entry constructor.
32
     *
33
     * @param $data
34
     */
35
    public function __construct($data)
36
    {
37
        $this->data = $data;
38
    }
39
40
    /**
41
     * Get the entry data
42
     *
43
     * @return array
44
     */
45
    public function getData()
46
    {
47
        return $this->data;
48
    }
49
50
    /**
51
     * Get the entry metadata
52
     *
53
     * @return array
54
     */
55
    public function getMetaData()
56
    {
57
        return $this->metadata;
58
    }
59
60
    public function offsetExists($offset)
61
    {
62
        return array_key_exists($offset, $this->data);
63
    }
64
65
    public function offsetGet($offset)
66
    {
67
        return $this->data[$offset];
68
    }
69
70
    public function offsetSet($offset, $value)
71
    {
72
        return $this->data[$offset] = $value;
73
    }
74
75
    public function offsetUnset($offset)
76
    {
77
        unset($this->data[$offset]);
78
    }
79
80
    public function __get($name)
81
    {
82
        if (array_key_exists($name, $this->data)) {
83
            return $this->data[$name];
84
        }
85
86
        throw new \InvalidArgumentException('Invalid property: ' . $name);
87
    }
88
89
    /**
90
     * Gets the object representation of this entry
91
     *
92
     * @return object
93
     */
94
    public function jsonSerialize()
95
    {
96
        return (object) [
97
            'metadata' => $this->getMetaData(),
98
            'fields' => $this->getData()
99
        ];
100
    }
101
}