Passed
Pull Request — master (#269)
by Christopher
02:59
created

ODataPropertyContent::current()   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 0
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
63
    public function offsetUnset($offset)
64
    {
65
        unset($this->properties[$offset]);
66
    }
67
68
    public function current()
69
    {
70
        return current($this->properties);
71
    }
72
73
    public function next()
74
    {
75
        return next($this->properties);
76
    }
77
78
    public function key()
79
    {
80
        return key($this->properties);
81
    }
82
83
    public function valid()
84
    {
85
        return key($this->properties) !== null;
86
    }
87
88
    public function rewind()
89
    {
90
        return reset($this->properties);
91
    }
92
93
    /**
94
     * Count elements of an object
95
     * @link https://php.net/manual/en/countable.count.php
96
     * @return int The custom count as an integer.
97
     * </p>
98
     * <p>
99
     * The return value is cast to an integer.
100
     * @since 5.1.0
101
     */
102
    public function count()
103
    {
104
        return count($this->properties);
105
    }
106
}
107