Passed
Push — heiglandreas-patch-1 ( 8f4377 )
by Andreas
03:21
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;
0 ignored issues
show
Bug introduced by
The type SocialConnect\Common\Entity\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
class Facebook extends \SocialConnect\OAuth2\AbstractProvider
15
{
16
    const NAME = 'facebook';
17
18 3
    public function getBaseUri()
19
    {
20 3
        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 2
    public function getIdentity(AccessTokenInterface $accessToken)
42
    {
43 2
        $query = [];
44
45 2
        $fields = $this->getArrayOption('identity.fields', []);
46 2
        if ($fields) {
47
            $query['fields'] = implode(',', $fields);
48
        }
49
50 2
        $response = $this->request(
51 2
            'GET',
52 2
            'me',
53
            $query,
54
            $accessToken
55
        );
56
57
        $hydrator = new ArrayHydrator([
58
            'id' => 'id',
59
            'first_name' => 'firstname',
60
            'last_name' => 'lastname',
61
            'email' => 'email',
62
            'gender' => static function ($value, User $user) {
63
                $user->setSex($value === 1 ? User::SEX_FEMALE : User::SEX_MALE);
64
            },
65
            'link' => 'url',
66
            'locale' => 'locale',
67
            'name' => 'fullname',
68
            'timezone' => 'timezone',
69
            'updated_time' => 'dateModified',
70
            'verified' => 'verified',
71
            'picture.data.url' => 'pictureURL'
72
        ]);
73
74
        /** @var User $user */
75
        $user = $hydrator->hydrate(new User(), $response);
76
        $user->emailVerified = true;
77
78
        return $user;
79
    }
80
}
81