PersonaResponse::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
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 string|null
20
     */
21
    protected $id;
22
23
    /**
24
     * @var string|null
25
     */
26
    protected $name;
27
28
    /**
29
     * @var string|null
30
     */
31
    protected $profilePictureUrl;
32
33
    /**
34
     * @var array
35
     */
36
    protected $data = [];
37
38
    /**
39
     * @var array|null
40
     */
41
    protected $paging;
42
43
    /**
44
     * @var bool
45
     */
46
    protected $success;
47
48 4
    protected function parseResponse(array $response): void
49
    {
50 4
        $this->id = $response[self::ID] ?? null;
51 4
        $this->name = $response[self::NAME] ?? null;
52 4
        $this->profilePictureUrl = $response[self::PROFILE_PICTURE_URL] ?? null;
53 4
        $this->success = $response[self::SUCCESS] ?? null;
54 4
        $this->paging = $response[self::PAGING] ?? null;
55
56 4
        $this->setData($response);
57 4
    }
58
59 4
    public function getId(): ?string
60
    {
61 4
        return $this->id;
62
    }
63
64 4
    public function getName(): ?string
65
    {
66 4
        return $this->name;
67
    }
68
69 4
    public function getProfilePictureUrl(): ?string
70
    {
71 4
        return $this->profilePictureUrl;
72
    }
73
74
    /**
75
     * @return \Kerox\Messenger\Model\Data[]
76
     */
77 4
    public function getData(): array
78
    {
79 4
        return $this->data;
80
    }
81
82 4
    public function isSuccess(): bool
83
    {
84 4
        return $this->success === true;
85
    }
86
87 4
    private function setData(array $response): void
88
    {
89 4
        if (isset($response[self::DATA]) && !empty($response[self::DATA])) {
90 1
            foreach ($response[self::DATA] as $data) {
91 1
                $this->data[] = Data::create($data);
92
            }
93
        }
94 4
    }
95
}
96