Completed
Pull Request — master (#1)
by BENOIT
07:29
created

ConfigurableTrait::unsetOption()   A

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 1
1
<?php
2
3
namespace BenTools\SimpleDBAL\Model;
4
5
trait ConfigurableTrait
6
{
7
    protected $options;
8
9
    /**
10
     * @param string $key
11
     * @return mixed
12
     */
13
    public function getOption($key)
14
    {
15
        if (null === $this->options) {
16
            $this->options = $this->getDefaultOptions();
17
        }
18
        return $this->options[$key] ?? null;
19
    }
20
21
    /**
22
     * @param string $key
23
     * @return bool
24
     */
25
    public function hasOption($key): bool
26
    {
27
        if (null === $this->options) {
28
            $this->options = $this->getDefaultOptions();
29
        }
30
        return array_key_exists($key, $this->options);
31
    }
32
33
    /**
34
     * @return array
35
     */
36
    public function getOptions(): array
37
    {
38
        if (null === $this->options) {
39
            $this->options = $this->getDefaultOptions();
40
        }
41
        return $this->options;
42
    }
43
44
    /**
45
     * @param string $key
46
     * @param mixed $value
47
     */
48
    public function setOption($key, $value): void
49
    {
50
        if (null === $this->options) {
51
            $this->options = $this->getDefaultOptions();
52
        }
53
        $this->options[$key] = $value;
54
    }
55
56
    /**
57
     * @return array
58
     */
59
    public function getDefaultOptions(): array
60
    {
61
        return [];
62
    }
63
}
64