Completed
Push — master ( 34d02e...659999 )
by Darío
02:25
created

ParamTrait::param()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 1
        return $parameters[$param];
48
    }
49
50
    /**
51
     * Set a parameter
52
     *
53
     * @param string $name
54
     * @param mixed $value
55
     *
56
     * @return null
57
     */
58
    public function setParam($name, $value)
59
    {
60
        $this->params[$name] = $value;
61
    }
62
63
    /**
64
     * Sets all parameters
65
     *
66
     * @param array $params
67
     *
68
     * @return null
69
     */
70 3
    public function setParams(Array $params)
71
    {
72 3
        $this->params = $params;
73 3
    }
74
75
    /**
76
     * Checks if a parameter exists
77
     *
78
     * @param string $param
79
     *
80
     * @return boolean
81
     */
82 1
    public function isParam($param)
83
    {
84 1
        $parameters = $this->getParams();
85
86 1
        if (array_key_exists($param, $parameters)) {
87 1
            return true;
88
        }
89
90
        return false;
91
    }
92
93
    /**
94
     * Returns a param (alias for getParam())
95
     *
96
     * @param string $paramName
97
     *
98
     * @return mixed
99
     */
100 1
    public function param($paramName)
101
    {
102 1
        return $this->getParam($paramName);
103
    }
104
}
105