Passed
Push — develop ( 3cbb1a...ed14bd )
by Mathieu
01:40
created

Service::__get()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 11
rs 10
ccs 6
cts 6
cp 1
crap 3
1
<?php
2
namespace Suricate;
3
4
use InvalidArgumentException;
5
6
class Service implements Interfaces\IService
7
{
8
    protected $parametersList   = [];
9
    protected $parametersValues = [];
10
11 10
    public function __construct()
12
    {
13
        // Service constructor
14 10
    }
15
16 9
    public function __get($variable)
17
    {
18 9
        if (in_array($variable, $this->parametersList)) {
19 8
            if (isset($this->parametersValues[$variable])) {
20 8
                return $this->parametersValues[$variable];
21
            }
22
23 2
            return null;
24
        }
25
26 1
        throw new InvalidArgumentException("Unknown configuration property " . get_called_class() . '->' .$variable);
27
    }
28
29 7
    public function __set($variable, $value)
30
    {
31 7
        if (in_array($variable, $this->parametersList)) {
32 6
            $this->parametersValues[$variable] = $value;
33
34 6
            return $this;
35
        }
36
37 2
        throw new InvalidArgumentException("Unknown configuration property " . get_called_class() . '->' . $variable);
38
    }
39
40 1
    public function configure($parameters = [])
41
    {
42 1
        foreach ($parameters as $key => $value) {
43 1
            $this->$key = $value;
44
        }
45
46 1
        $this->init();
47 1
    }
48
49 1
    public function getParameter($parameter)
50
    {
51 1
        return $this->$parameter;
52
    }
53
54 1
    protected function init()
55
    {
56 1
    }
57
}
58