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

Facebook::getName()   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 Facebook extends \SocialConnect\OAuth2\AbstractProvider
15
{
16
    const NAME = 'facebook';
17
18 4
    public function getBaseUri()
19
    {
20 4
        return 'https://graph.facebook.com/v3.3/';
21
    }
22
23 2
    public function getAuthorizeUri()
24
    {
25 2
        return 'https://www.facebook.com/dialog/oauth';
26
    }
27
28 2
    public function getRequestTokenUri()
29
    {
30 2
        return 'https://graph.facebook.com/oauth/access_token';
31
    }
32
33 3
    public function getName()
34
    {
35 3
        return self::NAME;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 3
    public function getIdentity(AccessTokenInterface $accessToken)
42
    {
43 3
        $query = [];
44
45 3
        $fields = $this->getArrayOption('identity.fields', []);
46 3
        if ($fields) {
47
            $query['fields'] = implode(',', $fields);
48
        }
49
50 3
        $response = $this->request(
51 3
            'GET',
52 3
            'me',
53
            $query,
54
            $accessToken
55
        );
56
57 1
        $hydrator = new ArrayHydrator([
58 1
            'id' => 'id',
59 1
            'first_name' => 'firstname',
60 1
            'last_name' => 'lastname',
61 1
            'email' => 'email',
62
            'gender' => static function ($value, User $user) {
63
                $user->setSex($value === 1 ? User::SEX_FEMALE : User::SEX_MALE);
0 ignored issues
show
Bug introduced by
The constant SocialConnect\Common\Entity\User::SEX_FEMALE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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

63
                /** @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...
Bug introduced by
The constant SocialConnect\Common\Entity\User::SEX_MALE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
64 1
            },
65 1
            'link' => 'url',
66 1
            'locale' => 'locale',
67 1
            'name' => 'fullname',
68 1
            'timezone' => 'timezone',
69 1
            'updated_time' => 'dateModified',
70 1
            'verified' => 'verified',
71 1
            'picture.data.url' => 'pictureURL'
72
        ]);
73
74
        /** @var User $user */
75 1
        $user = $hydrator->hydrate(new User(), $response);
76 1
        $user->emailVerified = true;
77
78 1
        return $user;
79
    }
80
}
81