EndpointConfiguration::offsetGet()   A
last analyzed

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
namespace hiapi\endpoints;
4
5
use hiapi\endpoints\Exception\EndpointBuildingException;
6
7
class EndpointConfiguration implements \ArrayAccess, EndpointConfigurationInterface
8
{
9
    private $config = [];
10
11
    public function set(string $property, $value): EndpointConfigurationInterface
12
    {
13
        if (array_key_exists($property, $this->config)) {
14
            throw new EndpointBuildingException(sprintf(
15
                'Property "%s" is already set, use $config->overwrite() if you want to change it.',
16
                $property
17
            ));
18
        }
19
20
        $this->config[$property] = $value;
21
22
        return $this;
23
    }
24
25
    public function overwrite(string $property, $value): EndpointConfigurationInterface
26
    {
27
        $this->unset($property);
28
29
        return $this->set($property, $value);
30
    }
31
32
    public function unset(string $property): EndpointConfigurationInterface
33
    {
34
        unset($this->config[$property]);
35
36
        return $this;
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42
    public function offsetExists($offset)
43
    {
44
        return isset($this->config);
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50
    public function offsetGet($offset)
51
    {
52
        return $this->config[$offset] ?? null;
53
    }
54
55
    /**
56
     * @inheritDoc
57
     */
58
    public function offsetSet($offset, $value)
59
    {
60
        $this->set($offset, $value);
61
    }
62
63
    /**
64
     * @inheritDoc
65
     */
66
    public function offsetUnset($offset)
67
    {
68
        $this->unset($offset);
69
    }
70
}
71