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

LinkedIn::getIdentity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1.0527

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
nc 1
nop 1
dl 0
loc 18
ccs 5
cts 8
cp 0.625
crap 1.0527
rs 9.9
c 3
b 0
f 0
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 * @author: Bogdan Popa https://github.com/icex <[email protected]>
6
 */
7
declare(strict_types=1);
8
9
namespace SocialConnect\OAuth2\Provider;
10
11
use SocialConnect\Common\ArrayHydrator;
12
use SocialConnect\Provider\AccessTokenInterface;
13
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...
14
15
class LinkedIn extends \SocialConnect\OAuth2\AbstractProvider
16
{
17
    const NAME = 'linkedin';
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 3
    public function getBaseUri()
23
    {
24 3
        return 'https://api.linkedin.com/v1/';
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 2
    public function getAuthorizeUri()
31
    {
32 2
        return 'https://www.linkedin.com/oauth/v2/authorization';
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 2
    public function getRequestTokenUri()
39
    {
40 2
        return 'https://www.linkedin.com/oauth/v2/accessToken';
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 3
    public function getName()
47
    {
48 3
        return self::NAME;
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54 2
    public function prepareRequest(string $method, string $uri, array &$headers, array &$query, AccessTokenInterface $accessToken = null): void
55
    {
56 2
        $query['format'] = 'json';
57
58 2
        if ($accessToken) {
59 2
            $headers['Authorization'] = "Bearer {$accessToken->getToken()}";
60
        }
61 2
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 2
    public function getIdentity(AccessTokenInterface $accessToken)
67
    {
68 2
        $response = $this->request(
69 2
            'GET',
70 2
            'people/~:(id,first-name,last-name,email-address,picture-url,location:(name))',
71 2
            [],
72
            $accessToken
73
        );
74
75
        $hydrator = new ArrayHydrator([
76
            'id'           => 'id',
77
            'emailAddress' => 'email',
78
            'firstName'    => 'firstname',
79
            'lastName'     => 'lastname',
80
            'pictureUrl'   => 'pictureURL',
81
        ]);
82
83
        return $hydrator->hydrate(new User(), $response);
84
    }
85
}
86