Completed
Pull Request — master (#6)
by Romain
02:01
created

AbstractResponse   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 43
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A decodeResponse() 0 4 1
parseResponse() 0 1 ?
A getResponse() 0 4 1
1
<?php
2
namespace Kerox\Messenger\Response;
3
4
use Psr\Http\Message\ResponseInterface;
5
6
abstract class AbstractResponse
7
{
8
9
    /**
10
     * @var \Psr\Http\Message\ResponseInterface
11
     */
12
    protected $response;
13
14
    /**
15
     * AbstractResponse constructor.
16
     *
17
     * @param \Psr\Http\Message\ResponseInterface $response
18
     */
19
    public function __construct(ResponseInterface $response)
20
    {
21
        $this->response = $response;
22
23
        $this->parseResponse($this->decodeResponse($response));
24
    }
25
26
    /**
27
     * @param \Psr\Http\Message\ResponseInterface $response
28
     * @return array
29
     */
30
    private function decodeResponse(ResponseInterface $response): array
31
    {
32
        return json_decode($response->getBody(), true);
33
    }
34
35
    /**
36
     * @param array $response
37
     * @return mixed
38
     */
39
    abstract protected function parseResponse(array $response);
40
41
    /**
42
     * @return \Psr\Http\Message\ResponseInterface
43
     */
44
    public function getResponse(): ResponseInterface
45
    {
46
        return $this->response;
47
    }
48
}
49