Total Complexity | 5 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
14 | final class ChannelAdapter implements AdapterInterface |
||
15 | { |
||
16 | /** |
||
17 | * @param string $content |
||
18 | * @return Channel |
||
19 | */ |
||
20 | public function convertJson(string $content): Channel |
||
21 | { |
||
22 | $channel = json_decode($content); |
||
23 | |||
24 | return $this->stdClassToChannel($channel); |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * @param string $content |
||
29 | * @return array|Channel[] |
||
30 | */ |
||
31 | public function convertJsonArray(string $content): array |
||
32 | { |
||
33 | $response = json_decode($content); |
||
34 | |||
35 | $array = []; |
||
36 | |||
37 | if (!empty($response->channels)) { |
||
38 | foreach ($response->channels as $channel) { |
||
39 | $array[] = $this->stdClassToChannel($channel); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | return $array; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param stdClass $channel |
||
48 | * @return Channel |
||
49 | */ |
||
50 | private function stdClassToChannel(stdClass $channel): Channel |
||
57 | ); |
||
58 | } |
||
59 | } |
||
60 |