Extractor::getFullName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Oryzone PHPoAuthUserData package <https://github.com/Oryzone/PHPoAuthUserData>.
5
 *
6
 * (c) Oryzone, developed by Luciano Mammino <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace OAuth\UserData\Extractor;
13
14
/**
15
 * Class Extractor
16
 * @package OAuth\UserData\Extractor
17
 */
18
class Extractor implements ExtractorInterface
19
{
20
    /**
21
     * @var \OAuth\Common\Service\ServiceInterface $service
22
     */
23
    protected $service;
24
25
    /**
26
     * Array of supported fields
27
     * @var array $supports
28
     */
29
    protected $supports;
30
31
    /**
32
     * Associative array with all the fields value
33
     * @var array
34
     */
35
    protected $fields;
36
37
    /**
38
     * Constructor
39
     *
40
     * @param array $supports
41
     * @param array $fields
42
     */
43
    public function __construct($supports = array(), $fields = array())
44
    {
45
        $this->supports = $supports;
46
        $this->fields = $fields;
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52
    public function supportsUniqueId()
53
    {
54
        return $this->isFieldSupported(self::FIELD_UNIQUE_ID);
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function getUniqueId()
61
    {
62
        return $this->getField(self::FIELD_UNIQUE_ID);
63
    }
64
65
    /**
66
     * {@inheritDoc}
67
     */
68
    public function supportsUsername()
69
    {
70
        return $this->isFieldSupported(self::FIELD_USERNAME);
71
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76
    public function getUsername()
77
    {
78
        return $this->getField(self::FIELD_USERNAME);
79
    }
80
81
    /**
82
     * {@inheritDoc}
83
     */
84
    public function supportsFirstName()
85
    {
86
        return $this->isFieldSupported(self::FIELD_FIRST_NAME);
87
    }
88
89
    /**
90
     * {@inheritDoc}
91
     */
92
    public function getFirstName()
93
    {
94
        return $this->getField(self::FIELD_FIRST_NAME);
95
    }
96
97
    /**
98
     * {@inheritDoc}
99
     */
100
    public function supportsLastName()
101
    {
102
        return $this->isFieldSupported(self::FIELD_LAST_NAME);
103
    }
104
105
    /**
106
     * {@inheritDoc}
107
     */
108
    public function getLastName()
109
    {
110
        return $this->getField(self::FIELD_LAST_NAME);
111
    }
112
113
    /**
114
     * {@inheritDoc}
115
     */
116
    public function supportsFullName()
117
    {
118
        return $this->isFieldSupported(self::FIELD_FULL_NAME);
119
    }
120
121
    /**
122
     * {@inheritDoc}
123
     */
124
    public function getFullName()
125
    {
126
        return $this->getField(self::FIELD_FULL_NAME);
127
    }
128
129
    /**
130
     * {@inheritDoc}
131
     */
132
    public function supportsEmail()
133
    {
134
        return $this->isFieldSupported(self::FIELD_EMAIL);
135
    }
136
137
    /**
138
     * {@inheritDoc}
139
     */
140
    public function getEmail()
141
    {
142
        return $this->getField(self::FIELD_EMAIL);
143
    }
144
145
    /**
146
     * {@inheritDoc}
147
     */
148
    public function supportsLocation()
149
    {
150
        return $this->isFieldSupported(self::FIELD_LOCATION);
151
    }
152
153
    /**
154
     * {@inheritDoc}
155
     */
156
    public function getLocation()
157
    {
158
        return $this->getField(self::FIELD_LOCATION);
159
    }
160
161
    /**
162
     * {@inheritDoc}
163
     */
164
    public function supportsDescription()
165
    {
166
        return $this->isFieldSupported(self::FIELD_DESCRIPTION);
167
    }
168
169
    /**
170
     * {@inheritDoc}
171
     */
172
    public function getDescription()
173
    {
174
        return $this->getField(self::FIELD_DESCRIPTION);
175
    }
176
177
    /**
178
     * {@inheritDoc}
179
     */
180
    public function supportsImageUrl()
181
    {
182
        return $this->isFieldSupported(self::FIELD_IMAGE_URL);
183
    }
184
185
    /**
186
     * {@inheritDoc}
187
     */
188
    public function getImageUrl()
189
    {
190
        return $this->getField(self::FIELD_IMAGE_URL);
191
    }
192
193
    /**
194
     * {@inheritDoc}
195
     */
196
    public function supportsProfileUrl()
197
    {
198
        return $this->isFieldSupported(self::FIELD_PROFILE_URL);
199
    }
200
201
    /**
202
     * {@inheritDoc}
203
     */
204
    public function getProfileUrl()
205
    {
206
        return $this->getField(self::FIELD_PROFILE_URL);
207
    }
208
209
    /**
210
     * {@inheritDoc}
211
     */
212
    public function supportsWebsites()
213
    {
214
        return $this->isFieldSupported(self::FIELD_WEBSITES);
215
    }
216
217
    /**
218
     * {@inheritDoc}
219
     */
220
    public function getWebsites()
221
    {
222
        return $this->getField(self::FIELD_WEBSITES);
223
    }
224
225
    /**
226
     * {@inheritDoc}
227
     */
228
    public function supportsVerifiedEmail()
229
    {
230
        return $this->isFieldSupported(self::FIELD_VERIFIED_EMAIL);
231
    }
232
233
    /**
234
     * {@inheritDoc}
235
     */
236
    public function isEmailVerified()
237
    {
238
        return $this->getField(self::FIELD_VERIFIED_EMAIL);
239
    }
240
241
    /**
242
     * {@inheritDoc}
243
     */
244
    public function supportsExtra()
245
    {
246
        return $this->isFieldSupported(self::FIELD_EXTRA);
247
    }
248
249
    /**
250
     * {@inheritDoc}
251
     */
252
    public function getExtra($key)
253
    {
254
        $extras = $this->getExtras();
255
256
        return (isset($extras[$key]) ? $extras[$key] : null);
257
    }
258
259
    /**
260
     * {@inheritDoc}
261
     */
262
    public function getExtras()
263
    {
264
        return $this->getField(self::FIELD_EXTRA);
265
    }
266
267
    /**
268
     * {@inheritDoc}
269
     */
270
    public function setService($service)
271
    {
272
        $this->service = $service;
273
    }
274
275
    /**
276
     * Get the value for a given field
277
     *
278
     * @param  string     $field the name of the field
279
     * @return null|mixed
280
     */
281
    protected function getField($field)
282
    {
283
        if ($this->isFieldSupported($field) && isset($this->fields[$field])) {
284
            return $this->fields[$field];
285
        }
286
287
        return null;
288
    }
289
290
    /**
291
     * Check if a given field is supported
292
     *
293
     * @param  string $field the name of the field
294
     * @return bool
295
     */
296
    protected function isFieldSupported($field)
297
    {
298
        return in_array($field, $this->supports);
299
    }
300
301
    /**
302
     * Get an array listing all fields names
303
     *
304
     * @return string[]
305
     */
306
    protected static function getAllFields()
307
    {
308
        return array(
309
            self::FIELD_UNIQUE_ID,
310
            self::FIELD_USERNAME,
311
            self::FIELD_FIRST_NAME,
312
            self::FIELD_LAST_NAME,
313
            self::FIELD_FULL_NAME,
314
            self::FIELD_EMAIL,
315
            self::FIELD_DESCRIPTION,
316
            self::FIELD_LOCATION,
317
            self::FIELD_PROFILE_URL,
318
            self::FIELD_IMAGE_URL,
319
            self::FIELD_WEBSITES,
320
            self::FIELD_VERIFIED_EMAIL,
321
            self::FIELD_EXTRA
322
        );
323
    }
324
}
325