Total Complexity | 5 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class DBOptionalValue implements OptionalValue { |
||
8 | /** |
||
9 | * @param object|array<string, mixed> $data |
||
10 | * @param string|string[] $path |
||
11 | * @param null|callable(): bool $validator |
||
12 | */ |
||
13 | public function __construct( |
||
14 | private object|array $data, |
||
15 | private string|array $path, |
||
16 | private $validator = null |
||
17 | ) {} |
||
18 | |||
19 | /** |
||
20 | * @return bool |
||
21 | */ |
||
22 | public function isValid(): bool { |
||
23 | if(!RecursiveStructureAccess::recursiveHas($this->data, $this->path)) { |
||
24 | return false; |
||
25 | } |
||
26 | if($this->validator !== null) { |
||
27 | $value = $this->getValue(); |
||
28 | return call_user_func($this->validator, $value); |
||
29 | } |
||
30 | return true; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @return mixed|null |
||
35 | */ |
||
36 | public function getValue() { |
||
38 | } |
||
39 | } |
||
40 |