Passed
Push — heiglandreas-patch-1 ( c6f183...8b9b12 )
by Andreas
03:32
created

Vk::getRequestTokenUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 */
6
declare(strict_types=1);
7
8
namespace SocialConnect\OAuth2\Provider;
9
10
use SocialConnect\Common\ArrayHydrator;
11
use SocialConnect\Provider\AccessTokenInterface;
12
use SocialConnect\Common\Entity\User;
13
14
class Vk extends \SocialConnect\OAuth2\AbstractProvider
15
{
16
    const NAME = 'vk';
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    protected $requestHttpMethod = 'GET';
22
23
    /**
24
     * Vk returns email inside AccessToken
25
     *
26
     * @var string|null
27
     */
28
    protected $email;
29
30 4
    public function getBaseUri()
31
    {
32 4
        return 'https://api.vk.com/';
33
    }
34
35 2
    public function getAuthorizeUri()
36
    {
37 2
        return 'https://oauth.vk.com/authorize';
38
    }
39
40 2
    public function getRequestTokenUri()
41
    {
42 2
        return 'https://oauth.vk.com/access_token';
43
    }
44
45 3
    public function getName()
46
    {
47 3
        return self::NAME;
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53 3
    public function prepareRequest(string $method, string $uri, array &$headers, array &$query, AccessTokenInterface $accessToken = null): void
54
    {
55 3
        if ($accessToken) {
56 3
            $query['access_token'] = $accessToken->getToken();
57
        }
58 3
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 3
    public function getIdentity(AccessTokenInterface $accessToken)
64
    {
65
        $query = [
66 3
            'v' => '5.100'
67
        ];
68
69 3
        $fields = $this->getArrayOption('identity.fields', []);
70 3
        if ($fields) {
71
            $query['fields'] = implode(',', $fields);
72
        }
73
74 3
        $response = $this->request('GET', 'method/users.get', $query, $accessToken);
75
76 1
        $hydrator = new ArrayHydrator([
77 1
            'id' => 'id',
78 1
            'first_name' => 'firstname',
79 1
            'last_name' => 'lastname',
80 1
            'email' => 'email',
81
            'bdate' => static function ($value, User $user) {
82
                $user->setBirthday(
83
                    new \DateTime($value)
84
                );
85 1
            },
86
            'sex' => static function ($value, User $user) {
87 1
                $user->setSex($value === 1 ? User::SEX_FEMALE : User::SEX_MALE);
0 ignored issues
show
Deprecated Code introduced by
The function SocialConnect\Common\Entity\User::setSex() has been deprecated: Use setGender instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

87
                /** @scrutinizer ignore-deprecated */ $user->setSex($value === 1 ? User::SEX_FEMALE : User::SEX_MALE);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The constant SocialConnect\Common\Entity\User::SEX_MALE has been deprecated: Use GENDER_MALE instead! ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

87
                $user->setSex($value === 1 ? User::SEX_FEMALE : /** @scrutinizer ignore-deprecated */ User::SEX_MALE);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
Deprecated Code introduced by
The constant SocialConnect\Common\Entity\User::SEX_FEMALE has been deprecated: Use GENDER_FEMALE instead! ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

87
                $user->setSex($value === 1 ? /** @scrutinizer ignore-deprecated */ User::SEX_FEMALE : User::SEX_MALE);

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
88 1
            },
89 1
            'screen_name' => 'username',
90 1
            'photo_max_orig' => 'pictureURL',
91
        ]);
92
93
        /** @var User $user */
94 1
        $user = $hydrator->hydrate(new User(), $response['response'][0]);
95
96 1
        $user->email = $this->email;
97 1
        $user->emailVerified = true;
98
99 1
        return $user;
100
    }
101
}
102