EndpointConfiguration   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 64
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 13 2
A overwrite() 0 6 1
A unset() 0 6 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 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