ConfigurableTrait::getOptions()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace BenTools\SimpleDBAL\Model;
4
5
trait ConfigurableTrait
6
{
7
8
    protected $options;
9
10
    /**
11
     * @param $key
12
     * @return mixed
13
     */
14
    public function getOption($key)
15
    {
16
        if (null === $this->options) {
17
            $this->options = $this->getDefaultOptions();
18
        }
19
        return $this->options[$key] ?? null;
20
    }
21
22
    /**
23
     * @param $key
24
     * @return bool
25
     */
26
    public function hasOption($key): bool
27
    {
28
        if (null === $this->options) {
29
            $this->options = $this->getDefaultOptions();
30
        }
31
        return array_key_exists($key, $this->options);
32
    }
33
34
    /**
35
     * @return array
36
     */
37
    public function getOptions(): array
38
    {
39
        if (null === $this->options) {
40
            $this->options = $this->getDefaultOptions();
41
        }
42
        return $this->options;
43
    }
44
45
    /**
46
     * @param $key
47
     * @param $value
48
     */
49
    public function setOption($key, $value)
50
    {
51
        if (null === $this->options) {
52
            $this->options = $this->getDefaultOptions();
53
        }
54
        $this->options[$key] = $value;
55
    }
56
57
    /**
58
     * @param $key
59
     */
60
    public function unsetOption($key)
61
    {
62
        if (null === $this->options) {
63
            $this->options = $this->getDefaultOptions();
64
        }
65
        unset($this->options[$key]);
66
    }
67
68
    /**
69
     * @return array
70
     */
71
    public function getDefaultOptions(): array
72
    {
73
        return [];
74
    }
75
}
76