Passed
Push — master ( 3583a4...4f8d46 )
by Romain
35s queued 10s
created

PersonaResponse::getProfilePictureUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Response;
6
7
use Kerox\Messenger\Model\Data;
8
9
class PersonaResponse extends AbstractResponse
10
{
11
    private const ID = 'id';
12
    private const NAME = 'name';
13
    private const PROFILE_PICTURE_URL = 'profile_picture_url';
14
    private const SUCCESS = 'success';
15
    private const DATA = 'data';
16
    private const PAGING = 'paging';
17
18
    /**
19
     * @var null|string
20
     */
21
    protected $id;
22
23
    /**
24
     * @var null|string
25
     */
26
    protected $name;
27
28
    /**
29
     * @var null|string
30
     */
31
    protected $profilePictureUrl;
32
33
    /**
34
     * @var array
35
     */
36
    protected $data = [];
37
38
    /**
39
     * @var null|array
40
     */
41
    protected $paging;
42
43
    /**
44
     * @var bool
45
     */
46
    protected $success;
47
48
    /**
49
     * @param array $response
50
     */
51 4
    protected function parseResponse(array $response): void
52
    {
53 4
        $this->id = $response[self::ID] ?? null;
54 4
        $this->name = $response[self::NAME] ?? null;
55 4
        $this->profilePictureUrl = $response[self::PROFILE_PICTURE_URL] ?? null;
56 4
        $this->success = $response[self::SUCCESS] ?? null;
57 4
        $this->paging = $response[self::PAGING] ?? null;
58
59 4
        $this->setData($response);
60 4
    }
61
62
    /**
63
     * @return null|string
64
     */
65 4
    public function getId(): ?string
66
    {
67 4
        return $this->id;
68
    }
69
70
    /**
71
     * @return null|string
72
     */
73 4
    public function getName(): ?string
74
    {
75 4
        return $this->name;
76
    }
77
78
    /**
79
     * @return null|string
80
     */
81 4
    public function getProfilePictureUrl(): ?string
82
    {
83 4
        return $this->profilePictureUrl;
84
    }
85
86
    /**
87
     * @return \Kerox\Messenger\Model\Data[]
88
     */
89 4
    public function getData(): array
90
    {
91 4
        return $this->data;
92
    }
93
94
    /**
95
     * @return bool
96
     */
97 4
    public function isSuccess(): bool
98
    {
99 4
        return $this->success === true;
100
    }
101
102
    /**
103
     * @param array $response
104
     */
105 4
    private function setData(array $response): void
106
    {
107 4
        if (isset($response[self::DATA]) && !empty($response[self::DATA])) {
108 1
            foreach ($response[self::DATA] as $data) {
109 1
                $this->data[] = Data::create($data);
110
            }
111
        }
112 4
    }
113
}
114