ResponseTransformer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 16
ccs 6
cts 6
cp 1
rs 10
wmc 2

1 Method

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