FacebookProvider::getAccessToken()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 14
loc 14
ccs 0
cts 12
cp 0
rs 9.4286
c 1
b 0
f 1
cc 1
eloc 9
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Sleepness\UberOAuthRestBundle\Provider;
4
5
use Sleepness\UberOAuthRestBundle\Provider\BaseOAuthProvider as BaseProvider;
6
use Sleepness\UberOAuthRestBundle\Model\User as UserDto;
7
8
class FacebookProvider extends BaseProvider
9
{
10
    const ACCESS_TOKEN_URL = 'https://graph.facebook.com/v2.5/oauth/access_token';
11
    const INFOS_URL = 'https://graph.facebook.com/v2.5/me';
12
    const PROVIDER_NAME = 'fb';
13
    const FIELDS = 'email,id,first_name,last_name';
14
15
    /**
16
     * @param $accessToken
17
     *
18
     * @return mixed|\Psr\Http\Message\ResponseInterface
19
     */
20 View Code Duplication
    public function getUserInformation($accessToken)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        $parameters = array(
23
            'access_token' => $accessToken->access_token,
24
            'fields' => self::FIELDS,
25
        );
26
27
        $url = $this->normalizeUrl(self::INFOS_URL, $parameters);
28
29
        $response = $this->doRequest($url, self::GET);
30
31
        return $response;
32
    }
33
34
    /**
35
     * @param $code
36
     *
37
     * @return mixed|\Psr\Http\Message\ResponseInterface
38
     */
39 View Code Duplication
    public function getAccessToken($code)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        $parameters = [
42
            'code' => $code,
43
            'grant_type' => 'authorization_code',
44
            'client_id' => $this->credentials['client_id'],
45
            'client_secret' => $this->credentials['client_secret'],
46
            'redirect_uri' => $this->credentials['redirect_uri'],
47
        ];
48
49
        $response = $this->doRequest($this->normalizeUrl(self::ACCESS_TOKEN_URL, $parameters), self::GET, $parameters);
50
51
        return $response;
52
    }
53
54
    /**
55
     * @param $code
56
     *
57
     * @return UserDto
58
     */
59 View Code Duplication
    public function getUser($code)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
    {
61
        $accessToken = $this->getAccessToken($code);
62
        $userInformation = $this->getUserInformation($accessToken);
63
64
        $user = new UserDto();
65
        $user->socialId = $userInformation->id;
66
        $user->email = $userInformation->email ?: null;
67
        $user->firstName = $userInformation->first_name ?: null;
68
        $user->lastName = $userInformation->last_name ?: null;
69
70
        return $user;
71
    }
72
}
73