Total Complexity | 4 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
11 | trait HasAttributes |
||
12 | { |
||
13 | /** |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $attributes = []; |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $requiredAttributes = []; |
||
22 | |||
23 | /** |
||
24 | * @var null|string |
||
25 | */ |
||
26 | protected $rootKey = null; |
||
27 | |||
28 | /** |
||
29 | * Verify the current attributes |
||
30 | * |
||
31 | * @return bool |
||
32 | * @throws MissingRequiredAttribute |
||
33 | */ |
||
34 | public function verifyAttributes() |
||
35 | { |
||
36 | foreach ($this->requiredAttributes as $required) { |
||
37 | |||
38 | if (!in_array($required, array_keys($this->attributes))) { |
||
39 | |||
40 | throw new MissingRequiredAttribute($required); |
||
41 | } |
||
42 | } |
||
43 | return true; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Output an array |
||
48 | * |
||
49 | * @return array |
||
50 | */ |
||
51 | public function toArray(): array |
||
54 | } |
||
55 | } |