OlxProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 67
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAuthUrl() 0 4 1
A getTokenUrl() 0 4 1
A getTokenFields() 0 10 1
A getUserByToken() 0 10 1
A mapUserToObject() 0 10 1
1
<?php
2
3
namespace NwLaravel\Socialite;
4
5
use Exception;
6
use Laravel\Socialite\Two\User;
7
use Laravel\Socialite\Two\ProviderInterface;
8
use Laravel\Socialite\Two\AbstractProvider;
9
10
class OlxProvider extends AbstractProvider implements ProviderInterface
11
{
12
    /**
13
     * The scopes being requested.
14
     *
15
     * @var array
16
     */
17
    protected $scopes = ['basic_user_info'];
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 1
    protected function getAuthUrl($state)
23
    {
24 1
        return $this->buildAuthUrlFromBase('https://auth.olx.com.br/oauth', $state);
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 1
    protected function getTokenUrl()
31
    {
32 1
        return 'https://auth.olx.com.br/oauth/token';
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    protected function getTokenFields($code)
39
    {
40
        return [
41 1
            'code' => $code,
42 1
            'client_id' => $this->clientId,
43 1
            'client_secret' => $this->clientSecret,
44 1
            'redirect_uri' => $this->redirectUrl,
45 1
            'grant_type' => 'authorization_code',
46 1
        ];
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 1
    protected function getUserByToken($token)
53
    {
54 1
        $userUrl = 'https://apps.olx.com.br/oauth_api/basic_user_info​?access_token='.$token;
55
56 1
        $response = $this->getHttpClient()->get($userUrl);
57
58 1
        $user = json_decode($response->getBody(), true);
59
60 1
        return $user;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 1
    protected function mapUserToObject(array $user)
67
    {
68 1
        return (new User)->setRaw($user)->map([
69 1
            'id'        => $user['user_email'],
70 1
            'nickname'  => null,
71 1
            'name'      => $user['user_name'],
72 1
            'email'     => $user['user_email'],
73 1
            'avatar'    => null,
74 1
        ]);
75
    }
76
}
77