Completed
Branch master (740422)
by Mathieu
02:04
created

Service   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 61
Duplicated Lines 32.79 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 20
loc 61
ccs 2
cts 3
cp 0.6667
rs 10
c 1
b 0
f 0
wmc 13
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __get() 12 12 3
A __set() 0 10 2
A configure() 0 12 3
A getParameter() 8 8 3
A init() 0 4 1

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
2
namespace Suricate;
3
4
use InvalidArgumentException;
5
6
class Service implements Interfaces\IService
7
{
8
    protected $parametersList   = array();
9
    protected $parametersValues = array();
10
11
    public function __construct()
12
    {
13
14
    }
15
16 View Code Duplication
    public function __get($variable)
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...
17
    {
18
        if (in_array($variable, $this->parametersList)) {
19
            if (isset($this->parametersValues[$variable])) {
20
                return $this->parametersValues[$variable];
21
            } else {
22
                return null;
23
            }
24
        } else {
25
            throw new InvalidArgumentException("Unknown configuration property " . get_called_class() . '->' .$variable);
26
        }
27
    }
28
29
    public function __set($variable, $value)
30
    {
31
        if (in_array($variable, $this->parametersList)) {
32
            $this->parametersValues[$variable] = $value;
33
34
            return $this;
35
        } else {
36
            throw new InvalidArgumentException("Unknown configuration property " . get_called_class() . '->' . $variable);
37
        }
38
    }
39
40
    public function configure($parameters = array())
41
    {
42
        foreach ($parameters as $key => $value) {
43
            if (in_array($key, $this->parametersList)) {
44
                $this->$key = $value;
45
            } else {
46
                throw new InvalidArgumentException("Unknown configuration property : " . get_called_class() . "->" . $key);
47
            }
48
        }
49
50
        $this->init();
51
    }
52
53 1 View Code Duplication
    public function getParameter($parameter)
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...
54
    {
55
        if (in_array($parameter, $this->parametersList)) {
56 1
            return isset($this->parametersValues[$parameter]) ? $this->parametersValues[$parameter] : null;
57
        } else {
58
            throw new InvalidArgumentException("Unknown configuration property : " . get_called_class() . "->" . $parameter);
59
        }
60
    }
61
62
    protected function init()
63
    {
64
        
65
    }
66
}
67