Passed
Push — master ( eb0fcb...47bdab )
by Gabriel
04:01 queued 10s
created

HasOptionsTrait::setOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 2
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
     * @param $key
15
     * @param $value
16
     * @return $this
17
     */
18 2
    public function setOption($key, $value)
19
    {
20 2
        $key = (string)$key;
21 2
        $this->_options[$key] = $value;
22
23 2
        return $this;
24
    }
25
26
    /**
27
     * @param string $key
28
     * @return bool
29
     */
30 6
    public function hasOption($key)
31
    {
32 6
        $key = (string)$key;
33
34 6
        return isset($this->_options[$key]);
35
    }
36
37
    /**
38
     * @param string $key
39
     * @return null
40
     */
41 3
    public function getOption($key)
42
    {
43 3
        $key = (string)$key;
44 3
        if (!$this->hasOption($key)) {
45 1
            return null;
46
        }
47
48 2
        return $this->_options[$key];
49
    }
50
}
51