Completed
Push — master ( e2173c...0d60f0 )
by Simonas
61:10
created

OptionsAwareTrait::hasOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\FilterManagerBundle\Filter\Helper;
13
14
/**
15
 * A trait which handles the behavior of options in filters.
16
 */
17
trait OptionsAwareTrait
18
{
19
    /**
20
     * @var array
21
     */
22
    private $options = [];
23
24
    /**
25
     * Checks if parameter exists.
26
     *
27
     * @param string $name
28
     *
29
     * @return bool
30
     */
31
    public function hasOption($name)
32
    {
33
        return isset($this->options[$name]);
34
    }
35
36
    /**
37
     * Removes parameter.
38
     *
39
     * @param string $name
40
     */
41
    public function removeOption($name)
42
    {
43
        if ($this->hasOption($name)) {
44
            unset($this->options[$name]);
45
        }
46
    }
47
48
    /**
49
     * Returns one parameter by it's name.
50
     *
51
     * @param string $name
52
     * @param string $default
53
     *
54
     * @return mixed
55
     */
56
    public function getOption($name, $default = null)
57
    {
58
        if ($this->hasOption($name)) {
59
            return $this->options[$name];
60
        }
61
        return $default;
62
    }
63
64
    /**
65
     * Returns an array of all options.
66
     *
67
     * @return array
68
     */
69
    public function getOptions()
70
    {
71
        return $this->options;
72
    }
73
74
    /**
75
     * @param string                 $name
76
     * @param array|string|\stdClass $value
77
     */
78
    public function addOption($name, $value)
79
    {
80
        $this->options[$name] = $value;
81
    }
82
83
    /**
84
     * Sets an array of options.
85
     *
86
     * @param array $options
87
     */
88
    public function setOptions(array $options)
89
    {
90
        $this->options = $options;
91
    }
92
}
93