Completed
Push — master ( 4f4939...8e0ded )
by Romain
14s
created

UserResponse::getLastAdReferral()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Response;
6
7
use Kerox\Messenger\Model\Referral;
8
use Kerox\Messenger\UserInterface;
9
10
class UserResponse extends AbstractResponse implements UserInterface
11
{
12
    /**
13
     * @var null|string
14
     */
15
    protected $firstName;
16
17
    /**
18
     * @var null|string
19
     */
20
    protected $lastName;
21
22
    /**
23
     * @var null|string
24
     */
25
    protected $profilePic;
26
27
    /**
28
     * @var null|string
29
     */
30
    protected $locale;
31
32
    /**
33
     * @var null|int
34
     */
35
    protected $timezone;
36
37
    /**
38
     * @var null|string
39
     */
40
    protected $gender;
41
42
    /**
43
     * @var null|bool
44
     */
45
    protected $paymentEnabled;
46
47
    /**
48
     * @var null|\Kerox\Messenger\Model\Referral
49
     */
50
    protected $lastAdReferral;
51
52
    /**
53
     * @param array $response
54
     */
55
    protected function parseResponse(array $response): void
56 2
    {
57
        $this->firstName = $response[UserInterface::FIRST_NAME] ?? null;
58 2
        $this->lastName = $response[UserInterface::LAST_NAME] ?? null;
59 2
        $this->profilePic = $response[UserInterface::PROFILE_PIC] ?? null;
60
        $this->locale = $response[UserInterface::LOCALE] ?? null;
61
        $this->timezone = $response[UserInterface::TIMEZONE] ?? null;
62
        $this->gender = $response[UserInterface::GENDER] ?? null;
63
        $this->paymentEnabled = $response[UserInterface::IS_PAYMENT_ENABLED] ?? null;
64 2
65
        $this->setLastAdReferral($response);
66 2
    }
67 2
68 2
    /**
69 2
     * @return null|string
70 2
     */
71 2
    public function getFirstName(): ?string
72 2
    {
73 2
        return $this->firstName;
74
    }
75 2
76 2
    /**
77
     * @return null|string
78
     */
79
    public function getLastName(): ?string
80
    {
81 1
        return $this->lastName;
82
    }
83 1
84
    /**
85
     * @return null|string
86
     */
87
    public function getProfilePic(): ?string
88
    {
89 1
        return $this->profilePic;
90
    }
91 1
92
    /**
93
     * @return null|string
94
     */
95
    public function getLocale(): ?string
96
    {
97 1
        return $this->locale;
98
    }
99 1
100
    /**
101
     * @return null|int
102
     */
103
    public function getTimezone(): ?int
104
    {
105 1
        return $this->timezone;
106
    }
107 1
108
    /**
109
     * @return null|string
110
     */
111
    public function getGender(): ?string
112
    {
113 1
        return $this->gender;
114
    }
115 1
116
    /**
117
     * @return null|bool
118
     */
119
    public function isPaymentEnabled(): ?bool
120
    {
121 1
        return $this->paymentEnabled;
122
    }
123 1
124
    /**
125
     * @return null|\Kerox\Messenger\Model\Referral
126
     */
127
    public function getLastAdReferral(): ?Referral
128
    {
129 1
        return $this->lastAdReferral;
130
    }
131 1
132
    /**
133
     * @param array $response
134
     */
135
    private function setLastAdReferral(array $response): void
136
    {
137 1
        if (isset($response[UserInterface::LAST_AD_REFERRAL])) {
138
            $this->lastAdReferral = Referral::create($response[UserInterface::LAST_AD_REFERRAL]);
139 1
        }
140
    }
141
}
142