| Conditions | 6 |
| Paths | 6 |
| Total Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | 5 | public static function send( |
|
| 13 | PsrResponseInterface $response |
||
| 14 | ) : Collection |
||
| 15 | { |
||
|
|
|||
| 16 | 5 | if (strpos($response->getHeaderLine('Content-Type'), 'application/json') !== false) { |
|
| 17 | 4 | $contents = json_decode($response->getBody()->getContents(), true); |
|
| 18 | if ( |
||
| 19 | 4 | ($response->getStatusCode() === 200) |
|
| 20 | 4 | && ! isset($contents['error']) |
|
| 21 | ) { |
||
| 22 | 3 | return new Collection($contents); |
|
| 23 | } else { |
||
| 24 | 1 | $code = isset($contents['error'])?$contents['error']:0; |
|
| 25 | 1 | $message = isset($contents['message'])?$contents['message']:''; |
|
| 26 | 1 | throw new LastFmException($message, $code); |
|
| 27 | } |
||
| 28 | } else { |
||
| 29 | 1 | $responseType = $response->getHeaderLine('Content-Type'); |
|
| 30 | 1 | throw new \InvalidArgumentException("Invalid response type {$responseType}"); |
|
| 31 | } |
||
| 33 | } |