Passed
Push — master ( ae841f...a81391 )
by Mathieu
17:45 queued 10:45
created

Service   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
eloc 23
c 5
b 1
f 0
dl 0
loc 74
ccs 28
cts 28
cp 1
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A configure() 0 4 2
A __set() 0 13 2
A __get() 0 15 3
A getParameter() 0 3 1
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 78
    public function __construct()
15
    {
16
        // Service constructor
17 78
    }
18
19 60
    /**
20
     * Service getter
21 60
     *
22 59
     * @param string $variable
23 59
     * @return void
24
     * @throws InvalidArgumentException
25
     */
26 5
    public function __get($variable)
27
    {
28
        if (in_array($variable, $this->parametersList)) {
29 1
            if (isset($this->parametersValues[$variable])) {
30
                return $this->parametersValues[$variable];
31 1
            }
32 1
33 1
            return null;
34
        }
35
36
        throw new InvalidArgumentException(
37 65
            "Unknown configuration property " .
38
                get_called_class() .
39 65
                '->' .
40 64
                $variable
41
        );
42 64
    }
43
44
    /**
45 2
     * Service setter
46
     *
47 2
     * @param string $variable
48 2
     * @param mixed $value
49 2
     * @throws InvalidArgumentException
50
     */
51
    public function __set($variable, $value)
52
    {
53 38
        if (in_array($variable, $this->parametersList)) {
54
            $this->parametersValues[$variable] = $value;
55 38
56 38
            return $this;
57
        }
58
59 38
        throw new InvalidArgumentException(
60 38
            "Unknown configuration property " .
61
                get_called_class() .
62 11
                '->' .
63
                $variable
64 11
        );
65
    }
66
67 38
    /**
68
     * Service configurator
69 38
     *
70
     * @param array $parameters
71
     * @return void
72
     */
73
    public function configure($parameters = [])
74
    {
75
        foreach ($parameters as $key => $value) {
76
            $this->$key = $value;
77
        }
78
    }
79
80
    public function getParameter($parameter)
81
    {
82
        return $this->$parameter;
83
    }
84
}
85