Passed
Push — master ( a22205...112e67 )
by Gabriel
04:04 queued 13s
created

HasOptionsTrait::hasOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Nip\Form\Elements\Traits;
4
5
/**
6
 * Trait HasOptionsTrait
7
 * @package Nip\Form\Elements\Traits
8
 */
9
trait HasOptionsTrait
10
{
11
    protected $_options;
12
13
    /**
14
     * @return mixed
15
     */
16 1
    public function getOptions()
17
    {
18 1
        return $this->_options;
19
    }
20
21
    /**
22
     * @param mixed $options
23
     */
24 5
    public function setOptions($options)
25
    {
26 5
        $this->_options = $options;
27 5
    }
28
29
    /**
30
     * @param $key
31
     * @param $value
32
     * @return $this
33
     */
34 2
    public function setOption($key, $value)
35
    {
36 2
        $key = (string)$key;
37 2
        $this->_options[$key] = $value;
38
39 2
        return $this;
40
    }
41
42
    /**
43
     * @param string $key
44
     * @return bool
45
     */
46 7
    public function hasOption($key)
47
    {
48 7
        $key = (string)$key;
49
50 7
        return isset($this->_options[$key]);
51
    }
52
53
    /**
54
     * @param string $key
55
     * @param null $default
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
56
     * @return null
57
     */
58 4
    public function getOption($key, $default = null)
59
    {
60 4
        $key = (string)$key;
61 4
        if (!$this->hasOption($key)) {
62 2
            return $default;
63
        }
64
65 2
        return $this->_options[$key];
66
    }
67
}
68