Response   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A send() 0 19 6
1
<?php
2
namespace Sourceout\LastFm\Http;
3
4
use Tightenco\Collect\Support\Collection;
5
use Sourceout\LastFm\Http\ResponseInterface;
6
use Psr\Http\Message\ResponseInterface as PsrResponseInterface;
7
use Sourceout\LastFm\Providers\LastFm\Exception\LastFmException;
8
9
class Response implements ResponseInterface
10
{
11
    /** @inheritDoc */
12 5
    public static function send(
13
        PsrResponseInterface $response
14
    ) : Collection
15
    {
0 ignored issues
show
Coding Style introduced by
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
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
        }
32
    }
33
}