Completed
Pull Request — master (#269)
by Christopher
14:37
created

ODataPropertyContent::offsetUnset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace POData\ObjectModel;
6
7
/**
8
 * Class ODataPropertyContent represents properties of a Complex type or entity element instance.
9
 */
10
class ODataPropertyContent implements \ArrayAccess, \Iterator, \Countable
11
{
12
    /**
13
     * The collection of properties.
14
     *
15
     * @var ODataProperty[]
16
     */
17
    private $properties = [];
18
19
    /**
20
     * ODataPropertyContent constructor.
21
     * @param ODataProperty[] $properties
22
     */
23
    public function __construct(array $properties)
24
    {
25
        $this->setPropertys($properties);
26
    }
27
28
    /**
29
     * @return ODataProperty[]
30
     */
31
    public function getPropertys(): array
32
    {
33
        return $this->properties;
34
    }
35
36
    /**
37
     * @param $newProperties ODataProperty[]
38
     * @return ODataPropertyContent
39
     */
40
    public function setPropertys(array $newProperties): self
41
    {
42
        $this->properties = $newProperties;
43
        return $this;
44
    }
45
46
    public function offsetExists($offset): bool
47
    {
48
        return array_key_exists($offset, $this->properties);
49
    }
50
51
    public function offsetGet($offset): ODataProperty
52
    {
53
        return $this->properties[$offset];
54
    }
55
56
    public function offsetSet($offset, $value)
57
    {
58
        assert($value instanceof ODataProperty);
59
        null === $offset ? $this->properties[] = $value : $this->properties[$offset] = $value;
60
    }
61
62
    public function offsetUnset($offset)
63
    {
64
        unset($this->properties[$offset]);
65
    }
66
67
    public function current()
68
    {
69
        return current($this->properties);
70
    }
71
72
    public function next()
73
    {
74
        return next($this->properties);
75
    }
76
77
    public function key()
78
    {
79
        return key($this->properties);
80
    }
81
82
    public function valid()
83
    {
84
        return key($this->properties) !== null;
85
    }
86
87
    public function rewind()
88
    {
89
        return reset($this->properties);
90
    }
91
92
    /**
93
     * Count elements of an object.
94
     * @see https://php.net/manual/en/countable.count.php
95
     * @return int The custom count as an integer.
96
     *             </p>
97
     *             <p>
98
     *             The return value is cast to an integer.
99
     * @since 5.1.0
100
     */
101
    public function count()
102
    {
103
        return count($this->properties);
104
    }
105
}
106