Total Complexity | 9 |
Total Lines | 78 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | abstract class AbstractResponse |
||
8 | { |
||
9 | /** @var array */ |
||
10 | const REQUIRED_KEYS = [ |
||
11 | 'cdr' => 'returnCode', |
||
12 | 'lib' => 'description', |
||
13 | 'version' => 'version', |
||
14 | 'reference' => 'reference', |
||
15 | ]; |
||
16 | |||
17 | /** @var string */ |
||
18 | public $returnCode; |
||
19 | |||
20 | /** @var string */ |
||
21 | public $description; |
||
22 | |||
23 | /** @var string */ |
||
24 | public $version; |
||
25 | |||
26 | /** @var string */ |
||
27 | public $reference; |
||
28 | |||
29 | /** |
||
30 | * AbstractResponse constructor. |
||
31 | * @param array $data |
||
32 | * @throws Exception |
||
33 | */ |
||
34 | public function __construct(array $data) |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @return array |
||
42 | */ |
||
43 | protected function getRequiredKeys(): array |
||
44 | { |
||
45 | return self::REQUIRED_KEYS; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param array $data |
||
50 | * @throws Exception |
||
51 | */ |
||
52 | private function validateRequiredKeys(array $data): void |
||
53 | { |
||
54 | $keys = $this->getRequiredKeys(); |
||
55 | foreach ($keys as $key => $value) { |
||
56 | if (!in_array($key, array_keys($data))) { |
||
57 | throw Exception::missingResponseKey($key); |
||
58 | } |
||
59 | } |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param array $data |
||
64 | */ |
||
65 | private function setDataRequiredKeys(array $data) |
||
66 | { |
||
67 | $keys = $this->getRequiredKeys(); |
||
68 | |||
69 | foreach ($data as $key => $value) { |
||
70 | if (isset($keys[$key])) { |
||
71 | $method = $keys[$key]; |
||
72 | $this->$method = $value; |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param string $eptCode |
||
79 | * @param string $companyCode |
||
80 | * @return bool |
||
81 | */ |
||
82 | public function validateSeal(string $eptCode, string $companyCode): bool |
||
85 | } |
||
86 | } |
||
87 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.