Total Complexity | 8 |
Total Lines | 70 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | trait Helper |
||
9 | { |
||
10 | /** |
||
11 | * @param $options |
||
12 | * @return bool|mixed |
||
13 | * |
||
14 | * @throws Exception |
||
15 | */ |
||
16 | public function isArray($options) |
||
17 | { |
||
18 | $this->validateOptions($options); |
||
19 | |||
20 | return $this->getFieldTypeOptionsValue($options, 'is-array', 'boolean'); |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * @param $options |
||
25 | * @return bool|mixed |
||
26 | * |
||
27 | * @throws Exception |
||
28 | */ |
||
29 | public function isCarbonDate($options) |
||
30 | { |
||
31 | $this->validateOptions($options); |
||
32 | |||
33 | return $this->getFieldTypeOptionsValue($options, 'is-carbon-date', 'boolean'); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @param $options |
||
38 | * |
||
39 | * @throws Exception |
||
40 | */ |
||
41 | private function validateOptions($options) |
||
42 | { |
||
43 | if (gettype($options) !== 'array') { |
||
44 | throw new Exception($options.' is not a valid array!'); |
||
45 | } |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param $value |
||
50 | * @param string $expected |
||
51 | * |
||
52 | * @throws Exception |
||
53 | */ |
||
54 | private function validateOptionValue($value, string $expected) |
||
55 | { |
||
56 | if (gettype($value) !== $expected) { |
||
57 | throw new Exception($value.' is not a valid '.$expected.' found '.gettype($value).'! Check on your model configurations.'); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param array $options |
||
63 | * @param string $key |
||
64 | * @param string $expected |
||
65 | * @return bool|mixed |
||
66 | * |
||
67 | * @throws Exception |
||
68 | */ |
||
69 | private function getFieldTypeOptionsValue(array $options, string $key, string $expected) |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 |