Completed
Push — master ( 3347ae...8ec7fe )
by Romain
9s
created

AbstractResponse::decodeResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Kerox\Messenger\Response;
3
4
use Psr\Http\Message\ResponseInterface;
5
6
abstract class AbstractResponse
7
{
8
9
    /**
10
     * AbstractResponse constructor.
11
     *
12
     * @param \Psr\Http\Message\ResponseInterface $response
13
     */
14
    public function __construct(ResponseInterface $response)
15
    {
16
        $this->parseResponse($this->decodeResponse($response));
17
    }
18
19
    /**
20
     * @param \Psr\Http\Message\ResponseInterface $response
21
     * @return array
22
     */
23
    private function decodeResponse(ResponseInterface $response): array
24
    {
25
        return json_decode($response->getBody(), true);
26
    }
27
28
    /**
29
     * @param array $response
30
     * @return mixed
31
     */
32
    abstract protected function parseResponse(array $response);
33
}
34