Passed
Push — main ( a3d595...383cbf )
by Dylan
02:02
created

ObjectResource::getIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Lifeboat\Resource;
4
5
use Lifeboat\Connector;
6
use IteratorAggregate;
7
use ArrayIterator;
8
9
/**
10
 * Class ResourceList
11
 * @package Lifeboat\Resource
12
 *
13
 * @property array $_object_data
14
 */
15
class ObjectResource extends ApiResource implements IteratorAggregate {
16
17
    private array $_object_data;
18
19
    /**
20
     * ObjectResource constructor.
21
     * @param Connector $client
22
     * @param array $_object_data
23
     */
24
    public function __construct(Connector $client, array $_object_data = [])
25
    {
26
        parent::__construct($client);
27
28
        foreach ($_object_data as $k => $v) {
29
            $this->__set($k, $v);
30
        }
31
    }
32
33
    /**
34
     * @param string $field
35
     * @return mixed
36
     */
37
    public function __get(string $field)
38
    {
39
        return $this->_object_data[$field] ?? null;
40
    }
41
42
    /**
43
     * @return ArrayIterator
44
     */
45
    public function getIterator(): ArrayIterator
46
    {
47
        return new ArrayIterator($this->_object_data);
48
    }
49
50
    /**
51
     * @param string $field
52
     * @param $value
53
     * @return $this
54
     */
55
    public function __set(string $field, $value): ObjectResource
56
    {
57
        $this->_object_data[$field] = $value;
58
        return $this;
59
    }
60
61
    public function offsetGet($offset)
62
    {
63
        return $this->_object_data[$offset] ?? null;
64
    }
65
66
    public function offsetSet($offset, $value)
67
    {
68
        return $this->_object_data[$offset] = $value;
69
    }
70
71
    /**
72
     * @param mixed $offset
73
     * @return void
74
     */
75
    public function offsetUnset($offset): void
76
    {
77
        unset($this->_object_data[$offset]);
78
    }
79
80
    /**
81
     * @param mixed $offset
82
     * @return bool
83
     */
84
    public function offsetExists($offset): bool
85
    {
86
        return array_key_exists($offset, $this->_object_data);
87
    }
88
89
    /**
90
     * @return int
91
     */
92
    public function count(): int
93
    {
94
        return count($this->_object_data);
95
    }
96
97
    /**
98
     * @return array
99
     */
100
    public function keys(): array
101
    {
102
        return \array_keys($this->_object_data);
103
    }
104
105
    /**
106
     * @return array
107
     */
108
    public function values(): array
109
    {
110
        return \array_values($this->_object_data);
111
    }
112
}
113