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

Facebook   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 93.94%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 32
c 3
b 1
f 0
dl 0
loc 65
ccs 31
cts 33
cp 0.9394
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getAuthorizeUri() 0 3 1
A getRequestTokenUri() 0 3 1
A getBaseUri() 0 3 1
A getIdentity() 0 38 3
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