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

Service::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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