VkProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 40.3 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 7
lcom 1
cbo 2
dl 27
loc 67
ccs 0
cts 35
cp 0
rs 10
c 2
b 1
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserInformation() 0 16 2
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 VkProvider extends BaseProvider
9
{
10
    const ACCESS_TOKEN_URL = 'https://oauth.vk.com/access_token';
11
    const INFOS_URL = 'https://api.vk.com/method/users.get';
12
    const PROVIDER_NAME = 'vk';
13
14
    /**
15
     * @param $accessToken
16
     *
17
     * @return mixed|\Psr\Http\Message\ResponseInterface
18
     */
19
    public function getUserInformation($accessToken)
20
    {
21
        $parameters = array(
22
            'access_token' => $accessToken->access_token,
23
        );
24
25
        $url = $this->normalizeUrl(self::INFOS_URL, $parameters);
26
27
        $response = $this->doRequest($url, self::GET);
28
29
        if (isset($accessToken->email)) {
30
            $response->response[0]->email = $accessToken->email;
31
        }
32
33
        return $response->response[0];
34
    }
35
36
    /**
37
     * @param $code
38
     *
39
     * @return mixed|\Psr\Http\Message\ResponseInterface
40
     */
41 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...
42
    {
43
        $parameters = [
44
            'code' => $code,
45
            'grant_type' => 'authorization_code',
46
            'client_id' => $this->credentials['client_id'],
47
            'client_secret' => $this->credentials['client_secret'],
48
            'redirect_uri' => $this->credentials['redirect_uri'],
49
        ];
50
51
        $response = $this->doRequest($this->normalizeUrl(self::ACCESS_TOKEN_URL, $parameters), self::GET, $parameters);
52
53
        return $response;
54
    }
55
56
    /**
57
     * @param $code
58
     *
59
     * @return UserDto
60
     */
61 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...
62
    {
63
        $accessToken = $this->getAccessToken($code);
64
        $userInformation = $this->getUserInformation($accessToken);
65
66
        $user = new UserDto();
67
        $user->socialId = $userInformation->uid;
68
        $user->email = $userInformation->email ?: null;
69
        $user->firstName = $userInformation->first_name ?: null;
70
        $user->lastName = $userInformation->last_name ?: null;
71
72
        return $user;
73
    }
74
}
75