Completed
Pull Request — master (#30)
by Romain
02:57 queued 31s
created

InsightsResponse   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 49
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parseResponse() 0 4 1
A getData() 0 4 1
A setData() 0 8 4
1
<?php
2
namespace Kerox\Messenger\Response;
3
4
use Kerox\Messenger\Model\Data;
5
use Psr\Http\Message\ResponseInterface;
6
7
class InsightsResponse extends AbstractResponse
8
{
9
10
    const DATA = 'data';
11
12
    /**
13
     * @var \Kerox\Messenger\Model\Data[]
14
     */
15
    protected $data = [];
16
17
    /**
18
     * InsightsResponse constructor.
19
     *
20
     * @param \Psr\Http\Message\ResponseInterface $response
21
     */
22 3
    public function __construct(ResponseInterface $response)
23
    {
24 3
        parent::__construct($response);
25 3
    }
26
27
    /**
28
     * @param array $response
29
     * @return void
30
     */
31 3
    protected function parseResponse(array $response)
32
    {
33 3
        $this->setData($response);
34 3
    }
35
36
    /**
37
     * @return \Kerox\Messenger\Model\Data[]
38
     */
39 3
    public function getData(): array
40
    {
41 3
        return $this->data;
42
    }
43
44
    /**
45
     * @param array $response
46
     */
47 3
    private function setData(array $response)
48
    {
49 3
        if (isset($response[self::DATA]) && !empty($response[self::DATA])) {
50 3
            foreach ($response[self::DATA] as $data) {
51 3
                $this->data[] = new Data($data);
52
            }
53
        }
54 3
    }
55
}
56