ParamTrait::getParam()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * DronePHP (http://www.dronephp.com)
4
 *
5
 * @link      http://github.com/Pleets/DronePHP
6
 * @copyright Copyright (c) 2016-2018 Pleets. (http://www.pleets.org)
7
 * @license   http://www.dronephp.com/license
8
 * @author    Darío Rivera <[email protected]>
9
 */
10
11
namespace Drone\Util;
12
13
/**
14
 * ParamTrait trait
15
 *
16
 * Standard parameters management
17
 */
18
trait ParamTrait
19
{
20
    /**
21
     * Current parameters
22
     *
23
     * @var array
24
     */
25
    protected $params = [];
26
27
    /**
28
     * Returns all parameters
29
     *
30
     * @return array
31
     */
32 1
    public function getParams()
33
    {
34 1
        return $this->params;
35
    }
36
37
    /**
38
     * Gets a particular parameter
39
     *
40
     * @param string $param
41
     *
42
     * @return string
43
     */
44 1
    public function getParam($param)
45
    {
46 1
        $parameters = $this->getParams();
47
48 1
        return $parameters[$param];
49
    }
50
51
    /**
52
     * Set a parameter
53
     *
54
     * @param string $name
55
     * @param mixed $value
56
     *
57
     * @return null
58
     */
59
    public function setParam($name, $value)
60
    {
61
        $this->params[$name] = $value;
62
    }
63
64
    /**
65
     * Sets all parameters
66
     *
67
     * @param array $params
68
     *
69
     * @return null
70
     */
71 3
    public function setParams(array $params)
72
    {
73 3
        $this->params = $params;
74 3
    }
75
76
    /**
77
     * Checks if a parameter exists
78
     *
79
     * @param string $param
80
     *
81
     * @return boolean
82
     */
83 1
    public function isParam($param)
84
    {
85 1
        $parameters = $this->getParams();
86
87 1
        if (array_key_exists($param, $parameters)) {
88 1
            return true;
89
        }
90
91
        return false;
92
    }
93
94
    /**
95
     * Returns a param (alias for getParam())
96
     *
97
     * @param string $paramName
98
     *
99
     * @return mixed
100
     */
101 1
    public function param($paramName)
102
    {
103 1
        return $this->getParam($paramName);
104
    }
105
}
106