Completed
Branch master (5acf81)
by Steevan
04:21
created

OptionTrait::setOption()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
3
namespace steevanb\SymfonyFormOptionsBuilder\Behavior;
4
5
trait OptionTrait
6
{
7
    /** @var array */
8
    protected $options = array();
9
10
    /**
11
     * @param string $name
12
     * @param mixed $value
13
     * @return $this
14
     */
15
    public function setOption($name, $value)
16
    {
17
        if ($value === Option::DEFAULT_VALUE) {
18
            $this->removeOption($name);
19
        } else {
20
            $this->options[$name] = $value;
21
        }
22
23
        return $this;
24
    }
25
26
    /**
27
     * @param string $name
28
     * @return mixed
29
     */
30
    public function getOption($name)
31
    {
32
        return (array_key_exists($name, $this->options)) ? $this->options[$name] : Option::DEFAULT_VALUE;
33
    }
34
35
    /**
36
     * @param string $name
37
     * @return $this
38
     */
39
    public function removeOption($name)
40
    {
41
        if (array_key_exists($name, $this->options)) {
42
            unset($this->options[$name]);
43
        }
44
45
        return $this;
46
    }
47
}
48