Completed
Push — 4.0 ( 0161d2...25fc97 )
by Marco
12:04
created

Parameters::get()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 31
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 31
rs 8.439
cc 6
eloc 12
nc 5
nop 2
1
<?php namespace Comodojo\Dispatcher\Components;
2
3
/**
4
 * @package     Comodojo Dispatcher
5
 * @author      Marco Giovinazzi <[email protected]>
6
 * @author      Marco Castiello <[email protected]>
7
 * @license     GPL-3.0+
8
 *
9
 * LICENSE:
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
26
trait Parameters {
27
28
    protected $parameters = array();
29
30
    final public function get($parameter=null, $index=null) {
31
32
        if ( is_null($parameter) ) return $this->parameters;
33
34
        else if ( array_key_exists($parameter, $this->parameters) ) {
35
            
36
            $value = $this->parameters[$parameter];
37
            
38
            if (is_array($value) && !is_null($index)) {
39
                
40
                if (isset($value[$index])) {
41
                
42
                    return $value[$index];
43
                    
44
                } else {
45
                    
46
                    return null;
47
                    
48
                }
49
                
50
            } else {
51
52
                return $value;
53
                
54
            }
55
56
        }
57
58
        else return null;
59
60
    }
61
62
    final public function set($parameter, $value) {
63
64
        $this->parameters[$parameter] = $value;
65
66
        return $this;
67
68
    }
69
70 View Code Duplication
    final public function delete($parameter = null) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
72
        if ( is_null($parameter) ) {
73
74
            $this->parameters = array();
75
76
            return true;
77
78
        } else if ( array_key_exists($parameter, $this->parameters) ) {
79
80
            unset($this->parameters[$parameter]);
81
82
            return true;
83
84
        } else {
85
86
            return false;
87
88
        }
89
90
    }
91
92
}
93