Completed
Push — menus ( a0a7c3 )
by Arnaud
02:33
created

Item::setId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/*
3
 * Copyright (c) Arnaud Ligny <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Cecil\Collection;
10
11
/**
12
 * Class Item.
13
 */
14
class Item implements ItemInterface
15
{
16
    /**
17
     * Item's identifier.
18
     *
19
     * @var string
20
     */
21
    protected $id;
22
23
    /**
24
     * Item properties.
25
     *
26
     * @var array
27
     */
28
    protected $properties = [];
29
30
    /**
31
     * Item constructor.
32
     *
33
     * @param string $id
34
     */
35
    public function __construct(string $id)
36
    {
37
        $this->setId($id);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function setId(string $id): BaseInterface
44
    {
45
        $this->id = $id;
46
47
        return $this;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getId(): string
54
    {
55
        return $this->id;
56
    }
57
58
    /**
59
     * Implement ArrayAccess.
60
     *
61
     * @param mixed $offset
62
     *
63
     * @return bool
64
     */
65
    public function offsetExists($offset)
66
    {
67
        return array_key_exists($offset, $this->properties);
68
    }
69
70
    /**
71
     * Implement ArrayAccess.
72
     *
73
     * @param mixed $offset
74
     *
75
     * @return null
76
     */
77
    public function offsetGet($offset)
78
    {
79
        return $this->properties[$offset];
80
    }
81
82
    /**
83
     * Implement ArrayAccess.
84
     *
85
     * @param mixed $offset
86
     * @param mixed $value
87
     */
88
    public function offsetSet($offset, $value)
89
    {
90
        $this->properties[$offset] = $value;
91
    }
92
93
    /**
94
     * Implement ArrayAccess.
95
     *
96
     * @param mixed $offset
97
     */
98
    public function offsetUnset($offset)
99
    {
100
        unset($this->properties[$offset]);
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function toArray(): array
107
    {
108
        return $this->properties;
109
    }
110
}
111