FacebookProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 61.54 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 1 Features 2
Metric Value
wmc 6
lcom 1
cbo 2
dl 40
loc 65
ccs 0
cts 33
cp 0
rs 10
c 3
b 1
f 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserInformation() 13 13 1
A getAccessToken() 14 14 1
A getUser() 13 13 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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