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

Item   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Test Coverage

Coverage 76.47%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 86
ccs 13
cts 17
cp 0.7647
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getId() 0 3 1
A setId() 0 5 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
A toArray() 0 3 1
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