| Total Complexity | 11 |
| Total Lines | 100 |
| Duplicated Lines | 0 % |
| Coverage | 92% |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 7 | class Model |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Model constructor. |
||
| 11 | * |
||
| 12 | * @param array $params |
||
| 13 | */ |
||
| 14 | 9 | public function __construct(array $params = []) |
|
| 15 | { |
||
| 16 | 9 | foreach ($params as $key => $value) { |
|
| 17 | 6 | $this->$key = $value; |
|
| 18 | } |
||
| 19 | 9 | } |
|
| 20 | |||
| 21 | /** |
||
| 22 | * List of allowed fields |
||
| 23 | * |
||
| 24 | * @return array |
||
| 25 | */ |
||
| 26 | protected function allowed(): array |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | private $required = []; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param array $required |
||
| 38 | */ |
||
| 39 | 4 | public function setRequired(array $required): void |
|
| 42 | 4 | } |
|
| 43 | |||
| 44 | /** |
||
| 45 | * List of required fields |
||
| 46 | * |
||
| 47 | * @return array |
||
| 48 | */ |
||
| 49 | 2 | private function required(): array |
|
| 50 | { |
||
| 51 | 2 | return $this->required; |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var array |
||
| 56 | */ |
||
| 57 | private $variables = []; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param string $name |
||
| 61 | * |
||
| 62 | * @return mixed |
||
| 63 | */ |
||
| 64 | 2 | public function __get(string $name) |
|
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param string $name |
||
| 71 | * @param mixed $value |
||
| 72 | * |
||
| 73 | * @throws InvalidArgumentException |
||
| 74 | */ |
||
| 75 | 8 | public function __set(string $name, $value) |
|
| 76 | { |
||
| 77 | 8 | if (!array_key_exists($name, $this->allowed())) { |
|
| 78 | 1 | throw new InvalidArgumentException("Argument $name is not allowed [" . implode(',', $this->allowed()) . ']'); |
|
| 79 | } |
||
| 80 | |||
| 81 | 8 | $this->variables[$name] = $value; |
|
| 82 | 8 | } |
|
| 83 | |||
| 84 | /** |
||
| 85 | * @param string $name |
||
| 86 | * |
||
| 87 | * @return bool |
||
| 88 | */ |
||
| 89 | 1 | public function __isset(string $name): bool |
|
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @return array |
||
| 96 | * @throws InvalidArgumentException |
||
| 97 | */ |
||
| 98 | 2 | public function toArray(): array |
|
| 109 |