Passed
Pull Request — master (#1676)
by Arnaud
05:15 queued 14s
created

Item::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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