ResponseTransformer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 24
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 16 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Codenixsv\BitfinexApi\Message;
6
7
use Codenixsv\BitfinexApi\Exception\TransformResponseException;
8
use Psr\Http\Message\ResponseInterface;
9
10
/**
11
 * Class ResponseTransformer
12
 * @package Codenixsv\BitfinexApi\Message
13
 */
14
class ResponseTransformer
15
{
16
    /**
17
     * @param ResponseInterface $response
18
     * @return array
19
     * @throws TransformResponseException
20
     */
21 15
    public function transform(ResponseInterface $response): array
22
    {
23 15
        $body = (string) $response->getBody();
24 15
        if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) {
25 14
            $content = json_decode($body, true);
26 14
            if (JSON_ERROR_NONE === json_last_error()) {
27 13
                return $content;
28
            }
29
30 1
            throw new TransformResponseException('Error transforming response to array. JSON_ERROR: '
31 1
                . json_last_error());
32
        }
33
34 1
        throw new TransformResponseException('Error transforming response to array. Content-Type 
35
            is not application/json');
36
    }
37
}
38