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

Parameters   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 67
Duplicated Lines 31.34 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
c 2
b 0
f 0
lcom 1
cbo 0
dl 21
loc 67
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B get() 0 31 6
A set() 0 7 1
A delete() 21 21 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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