Completed
Pull Request — master (#2)
by Mathieu
05:06 queued 01:16
created

Service   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 50
rs 10
ccs 21
cts 21
cp 1
wmc 10

6 Methods

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