| Conditions | 5 |
| Paths | 3 |
| Total Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | public function count(ResponseInterface $response): int |
||
| 30 | { |
||
| 31 | $json = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); |
||
| 32 | |||
| 33 | if (!isset($json['data']['children'])) { |
||
| 34 | throw new FetchException('The "data.children" attributes could not be found', $response->getBody()->getContents()); |
||
| 35 | } |
||
| 36 | |||
| 37 | $count = 0; |
||
| 38 | if (isset($json['data']['children'])) { |
||
| 39 | foreach ((array) $json['data']['children'] as $child) { |
||
| 40 | if (isset($child['data']['score'])) { |
||
| 41 | $count += $child['data']['score']; |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | return $count; |
||
| 47 | } |
||
| 48 | } |
||
| 49 |