Service::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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