Total Complexity | 8 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 6 | ||
Bugs | 3 | Features | 0 |
1 | <?php |
||
14 | class DataSearchDecoder |
||
15 | { |
||
16 | /** |
||
17 | * @throws InvalidServerResponseException |
||
18 | * @throws NotFoundException |
||
19 | */ |
||
20 | public static function decode(SearchResponseRaw $searchResponseRaw): SearchDataResponse |
||
21 | { |
||
22 | if ('' === $searchResponseRaw->getDaneSzukajPodmiotyResult()) { |
||
23 | return new SearchDataResponse(); |
||
24 | } |
||
25 | |||
26 | try { |
||
27 | $xmlElementsResponse = new SimpleXMLElement($searchResponseRaw->getDaneSzukajPodmiotyResult()); |
||
28 | } catch (\Exception $e) { |
||
29 | throw new InvalidServerResponseException('Invalid server response', 0, $e); |
||
30 | } |
||
31 | |||
32 | $elements = []; |
||
33 | |||
34 | foreach ($xmlElementsResponse->dane as $resultData) { |
||
35 | $elements[] = self::decodeSingleResult($resultData); |
||
|
|||
36 | } |
||
37 | |||
38 | return new SearchDataResponse($elements); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @throws NotFoundException |
||
43 | */ |
||
44 | private static function decodeSingleResult(SimpleXMLElement $element): SearchResponseCompanyData |
||
57 | } |
||
58 | } |
||
59 |