Total Complexity | 9 |
Total Lines | 67 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class Ressource |
||
9 | { |
||
10 | /** @var array */ |
||
11 | protected $parameters = []; |
||
12 | |||
13 | /** @var array */ |
||
14 | protected $keys = []; |
||
15 | |||
16 | /** |
||
17 | * Ressource constructor. |
||
18 | * @param array $fields |
||
19 | * @throws Exception |
||
20 | */ |
||
21 | public function __construct(array $fields = []) |
||
22 | { |
||
23 | $this->setParameters($fields); |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * @param string $name |
||
28 | * @return mixed |
||
29 | * @throws Exception |
||
30 | */ |
||
31 | public function getParameter(string $name) |
||
32 | { |
||
33 | if (!in_array($name, $this->keys, true)) { |
||
34 | throw Exception::invalidResourceParameter($name); |
||
35 | } |
||
36 | |||
37 | if (isset($this->parameters[$name]) === false) { |
||
38 | return null; |
||
39 | } |
||
40 | |||
41 | return $this->parameters[$name]; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @param string $name |
||
46 | * @param mixed $value |
||
47 | * @throws Exception |
||
48 | */ |
||
49 | public function setParameter(string $name, $value = null): void |
||
50 | { |
||
51 | if (!in_array($name, $this->keys, true)) { |
||
52 | throw Exception::invalidResourceParameter($name); |
||
53 | } |
||
54 | |||
55 | $this->parameters[$name] = $value; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @param array $fields |
||
60 | * @throws Exception |
||
61 | */ |
||
62 | public function setParameters(array $fields): void |
||
66 | } |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return array |
||
71 | */ |
||
72 | public function getParameters(): array |
||
75 | } |
||
76 | } |
||
77 |