Completed
Push — master ( 046422...8eb4ac )
by ARCANEDEV
08:13 queued 14s
created

TwitterProvider::user()   B

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