TwitterProvider::user()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 0
cts 23
cp 0
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 17
nc 2
nop 0
crap 6
1
<?php namespace Arcanedev\Socialite\OAuth\One;
2
3
use InvalidArgumentException;
4
5
/**
6
 * Class     TwitterProvider
7
 *
8
 * @package  Arcanedev\Socialite\OAuth\One
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class TwitterProvider extends AbstractProvider
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Main Functions
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function user()
21
    {
22
        if ( ! $this->hasNecessaryVerifier()) {
23
            throw new InvalidArgumentException(
24
                'Invalid request. Missing OAuth verifier.'
25
            );
26
        }
27
28
        $user         = $this->server->getUserDetails($token = $this->getToken());
29
        $extraDetails = [
30
            'location'    => $user->location,
31
            'description' => $user->description,
32
        ];
33
34
        $instance = (new User)->setRaw(array_merge($user->extra, $user->urls, $extraDetails))
35
            ->setToken($token->getIdentifier(), $token->getSecret());
36
37
        return $instance->map([
38
            'id'              => $user->uid,
39
            'nickname'        => $user->nickname,
40
            'name'            => $user->name,
41
            'email'           => $user->email,
42
            'avatar'          => $user->imageUrl,
43
            'avatar_original' => str_replace('_normal', '', $user->imageUrl),
44
        ]);
45
    }
46
}
47