Completed
Branch develop (8166a6)
by Romain
01:52
created

UserResponse::parseResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
namespace Kerox\Messenger\Response;
3
4
use Kerox\Messenger\UserInterface;
5
use Psr\Http\Message\ResponseInterface;
6
7
class UserResponse extends AbstractResponse implements UserInterface
8
{
9
10
    /**
11
     * @var null|string
12
     */
13
    protected $firstName;
14
15
    /**
16
     * @var null|string
17
     */
18
    protected $lastName;
19
20
    /**
21
     * @var null|string
22
     */
23
    protected $profilePic;
24
25
    /**
26
     * @var null|string
27
     */
28
    protected $locale;
29
30
    /**
31
     * @var null|int
32
     */
33
    protected $timezone;
34
35
    /**
36
     * @var null|string
37
     */
38
    protected $gender;
39
40
    /**
41
     * @var null|bool
42
     */
43
    protected $isPaymentEnabled;
44
45
    /**
46
     * UserProfileResponse constructor.
47
     * @param \Psr\Http\Message\ResponseInterface $response
48
     */
49
    public function __construct(ResponseInterface $response)
50
    {
51
        parent::__construct($response);
52
    }
53
54
    /**
55
     * @param array $response
56
     * @return void
57
     */
58
    protected function parseResponse(array $response)
59
    {
60
        $this->setFirstName($response);
61
        $this->setLastName($response);
62
        $this->setProfilePic($response);
63
        $this->setLocale($response);
64
        $this->setTimezone($response);
65
        $this->setGender($response);
66
        $this->setIsPaymentEnabled($response);
67
    }
68
69
    /**
70
     * @return null|string
71
     */
72
    public function getFirstName()
73
    {
74
        return $this->firstName;
75
    }
76
77
    /**
78
     * @param array $response
79
     * @return void
80
     */
81
    private function setFirstName(array $response)
82
    {
83
        if (isset($response[self::FIRST_NAME])) {
84
            $this->firstName = $response[self::FIRST_NAME];
85
        }
86
    }
87
88
    /**
89
     * @return null|string
90
     */
91
    public function getLastName()
92
    {
93
        return $this->lastName;
94
    }
95
96
    /**
97
     * @param array $response
98
     * @return void
99
     */
100
    private function setLastName(array $response)
101
    {
102
        if (isset($response[self::LAST_NAME])) {
103
            $this->lastName = $response[self::LAST_NAME];
104
        }
105
    }
106
107
    /**
108
     * @return null|string
109
     */
110
    public function getProfilePic()
111
    {
112
        return $this->profilePic;
113
    }
114
115
    /**
116
     * @param array $response
117
     * @return void
118
     */
119
    private function setProfilePic(array $response)
120
    {
121
        if (isset($response[self::PROFILE_PIC])) {
122
            $this->profilePic = $response[self::PROFILE_PIC];
123
        }
124
    }
125
126
    /**
127
     * @return null|string
128
     */
129
    public function getLocale()
130
    {
131
        return $this->locale;
132
    }
133
134
    /**
135
     * @param array $response
136
     * @return void
137
     */
138
    private function setLocale(array $response)
139
    {
140
        if (isset($response[self::LOCALE])) {
141
            $this->locale = $response[self::LOCALE];
142
143
        }
144
    }
145
146
    /**
147
     * @return int|null
148
     */
149
    public function getTimezone()
150
    {
151
        return $this->timezone;
152
    }
153
154
    /**
155
     * @param array $response
156
     * @return void
157
     */
158
    private function setTimezone(array $response)
159
    {
160
        if (isset($response[self::TIMEZONE])) {
161
            $this->timezone = $response[self::TIMEZONE];
162
        }
163
    }
164
165
    /**
166
     * @return null|string
167
     */
168
    public function getGender()
169
    {
170
        return $this->gender;
171
    }
172
173
    /**
174
     * @param array $response
175
     * @return void
176
     */
177
    private function setGender(array $response)
178
    {
179
        if (isset($response[self::GENDER])) {
180
            $this->gender = $response[self::GENDER];
181
        }
182
    }
183
184
    /**
185
     * @return bool|null
186
     */
187
    public function getIsPaymentEnabled()
188
    {
189
        return $this->isPaymentEnabled;
190
    }
191
192
    /**
193
     * @param array $response
194
     * @return void
195
     */
196
    private function setIsPaymentEnabled(array $response)
197
    {
198
        if (isset($response[self::IS_PAYMENT_ENABLED])) {
199
            $this->isPaymentEnabled = $response[self::IS_PAYMENT_ENABLED];
200
        }
201
    }
202
}
203