Completed
Push — include-lib ( fd24a6...4173d3 )
by Arnaud
13:24
created

Item::offsetUnset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
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 properties.
18
     *
19
     * @var array
20
     */
21
    protected $properties = [];
22
23
    /**
24
     * AbstractItem constructor.
25
     *
26
     * @param string $id
27
     */
28
    public function __construct($id = '')
29
    {
30
        $this->setId($id);
31
    }
32
33
    /**
34
     * If parameter is empty uses the object hash
35
     * {@inheritdoc}
36
     */
37
    public function setId($id = '')
38
    {
39
        if (empty($id)) {
40
            $id = spl_object_hash($this);
41
        }
42
        $this->offsetSet('id', $id);
43
44
        return $this;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getId()
51
    {
52
        return $this->offsetGet('id');
53
    }
54
55
    /**
56
     * Implement ArrayAccess.
57
     *
58
     * @param mixed $offset
59
     *
60
     * @return bool
61
     */
62
    public function offsetExists($offset)
63
    {
64
        return array_key_exists($offset, $this->properties);
65
    }
66
67
    /**
68
     * Implement ArrayAccess.
69
     *
70
     * @param mixed $offset
71
     *
72
     * @return null
73
     */
74
    public function offsetGet($offset)
75
    {
76
        return $this->properties[$offset];
77
    }
78
79
    /**
80
     * Implement ArrayAccess.
81
     *
82
     * @param mixed $offset
83
     * @param mixed $value
84
     */
85
    public function offsetSet($offset, $value)
86
    {
87
        $this->properties[$offset] = $value;
88
    }
89
90
    /**
91
     * Implement ArrayAccess.
92
     *
93
     * @param mixed $offset
94
     */
95
    public function offsetUnset($offset)
96
    {
97
        unset($this->properties[$offset]);
98
    }
99
}
100