| Total Complexity | 10 |
| Total Lines | 71 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 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)) { |
||
| 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): void |
||
| 50 | { |
||
| 51 | if (!in_array($name, $this->keys)) { |
||
| 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 |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @return array |
||
| 75 | */ |
||
| 76 | public function getParameters(): array |
||
| 79 | } |
||
| 80 | } |
||
| 81 |