ParametersTrait   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 86
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A hasParameter() 0 4 1
A removeParameter() 0 6 2
A getParameter() 0 4 1
A getParameters() 0 4 1
A addParameter() 0 4 1
A setParameters() 0 6 1
A processArray() 0 4 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\ElasticsearchDSL;
13
14
/**
15
 * A trait which handles the behavior of parameters in queries, filters, etc.
16
 */
17
trait ParametersTrait
18
{
19
    /**
20
     * @var array
21
     */
22
    private $parameters = [];
23
24
    /**
25
     * Checks if parameter exists.
26
     *
27
     * @param string $name
28
     *
29
     * @return bool
30
     */
31
    public function hasParameter($name)
32
    {
33
        return isset($this->parameters[$name]);
34
    }
35
36
    /**
37
     * Removes parameter.
38
     *
39
     * @param string $name
40
     */
41
    public function removeParameter($name)
42
    {
43
        if ($this->hasParameter($name)) {
44
            unset($this->parameters[$name]);
45
        }
46
    }
47
48
    /**
49
     * Returns one parameter by it's name.
50
     *
51
     * @param string $name
52
     *
53
     * @return array|string|int|float|bool|\stdClass
54
     */
55
    public function getParameter($name)
56
    {
57
        return $this->parameters[$name];
58
    }
59
60
    /**
61
     * Returns an array of all parameters.
62
     *
63
     * @return array
64
     */
65
    public function getParameters()
66
    {
67
        return $this->parameters;
68
    }
69
70
    /**
71
     * @param string                 $name
72
     * @param array|string|int|float|bool|\stdClass $value
73
     */
74
    public function addParameter($name, $value)
75
    {
76
        $this->parameters[$name] = $value;
77
    }
78
79
    /**
80
     * @param array $parameters
81
     *
82
     * @return $this
83
     */
84
    public function setParameters(array $parameters)
85
    {
86
        $this->parameters = $parameters;
87
88
        return $this;
89
    }
90
91
    /**
92
     * Returns given array merged with parameters.
93
     *
94
     * @param array $array
95
     *
96
     * @return array
97
     */
98
    protected function processArray(array $array = [])
99
    {
100
        return array_merge($array, $this->parameters);
101
    }
102
}
103