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