Completed
Push — develop ( 2e1df2...27dbda )
by Mathieu
03:22
created

Service::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 1
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 7
    public function __construct()
12
    {
13
        // Service constructor
14 7
    }
15
16 5
    public function __get($variable)
17
    {
18 5
        if (in_array($variable, $this->parametersList)) {
19 4
            if (isset($this->parametersValues[$variable])) {
20 4
                return $this->parametersValues[$variable];
21
            } else {
22
                return null;
23
            }
24
        } else {
25 1
            throw new InvalidArgumentException("Unknown configuration property " . get_called_class() . '->' .$variable);
26
        }
27
    }
28
29 5
    public function __set($variable, $value)
30
    {
31 5
        if (in_array($variable, $this->parametersList)) {
32 4
            $this->parametersValues[$variable] = $value;
33
34 4
            return $this;
35
        } else {
36 1
            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
    public function getParameter($parameter)
54
    {
55 1
        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