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

AbstractResponse   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A decodeResponse() 0 4 1
parseResponse() 0 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