Total Complexity | 8 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | abstract class RequestModel implements RequestModelInterface |
||
10 | { |
||
11 | private array $requestData = []; |
||
12 | |||
13 | 20 | public function setRequestData(array $requestData): void |
|
16 | 20 | } |
|
17 | |||
18 | 17 | public function getValue(string $field, $default = null) |
|
19 | { |
||
20 | 17 | if ($this->isOptionalField($field)) { |
|
21 | 9 | $value = ArrayHelper::getValueByPath($this->requestData, $field); |
|
22 | 9 | if (empty($value)) { |
|
23 | 5 | return $default; |
|
24 | } |
||
25 | } |
||
26 | |||
27 | 12 | return ArrayHelper::getValueByPath($this->requestData, $field, $default); |
|
28 | } |
||
29 | |||
30 | 1 | public function hasValue(string $field): bool |
|
31 | { |
||
32 | 1 | return $this->getValue($field) !== null; |
|
33 | } |
||
34 | |||
35 | 2 | public function getRequestData(): array |
|
36 | { |
||
37 | 2 | return $this->requestData; |
|
38 | } |
||
39 | |||
40 | 11 | public function getOptionalFields(): array |
|
43 | } |
||
44 | |||
45 | 17 | private function isOptionalField(string $field): bool |
|
48 | } |
||
49 | } |
||
50 |