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

Entry   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 84
ccs 0
cts 42
cp 0
rs 10
c 1
b 0
f 0
wmc 10
lcom 1
cbo 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getData() 0 4 1
A getMetaData() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
A __get() 0 8 2
A jsonSerialize() 0 7 1
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
}