Passed
Push — master ( b0fdbe...fe6987 )
by Zbigniew
02:56
created

isSupportedResponseFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the zibios/wrike-php-library package.
7
 *
8
 * (c) Zbigniew Ślązak
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zibios\WrikePhpLibrary\Transformer\Response\Psr;
15
16
use Psr\Http\Message\ResponseInterface;
17
use Psr\Http\Message\StreamInterface;
18
use Zibios\WrikePhpLibrary\Transformer\ResponseTransformerInterface;
19
20
/**
21
 * Abstract Response Transformer for PSR Response from HTTP Client.
22
 */
23
abstract class AbstractPsrResponseTransformer implements ResponseTransformerInterface
24
{
25
    /**
26
     * @param ResponseInterface $response
27
     *
28
     * @return ResponseInterface
29
     */
30 86
    protected function transformToPsrResponse(ResponseInterface $response): ResponseInterface
31
    {
32 86
        return $response;
33
    }
34
35
    /**
36
     * @param ResponseInterface $response
37
     *
38
     * @return StreamInterface
39
     */
40 84
    protected function transformToPsrBody(ResponseInterface $response): StreamInterface
41
    {
42 84
        return $this->transformToPsrResponse($response)->getBody();
43
    }
44
45
    /**
46
     * @param ResponseInterface $response
47
     *
48
     * @throws \RuntimeException
49
     *
50
     * @return string
51
     */
52 82
    protected function transformToStringBody(ResponseInterface $response): string
53
    {
54 82
        return $this->transformToPsrBody($response)->getContents();
55
    }
56
57
    /**
58
     * @param ResponseInterface $response
59
     *
60
     * @throws \RuntimeException
61
     *
62
     * @return array
63
     */
64 80
    protected function transformToArrayBody(ResponseInterface $response): array
65
    {
66 80
        return json_decode($this->transformToStringBody($response), true);
67
    }
68
}
69