WordPress::prepareRequest()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 2
nop 5
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
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 WordPress extends \SocialConnect\OAuth2\AbstractProvider
15
{
16
    const NAME = 'wordpress';
17
18
    /**
19
     * {@inheritdoc}
20
     */
21 4
    public function getBaseUri()
22
    {
23 4
        return 'https://public-api.wordpress.com/rest/v1/';
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 2
    public function getAuthorizeUri()
30
    {
31 2
        return 'https://public-api.wordpress.com/oauth2/authorize';
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 2
    public function getRequestTokenUri()
38
    {
39 2
        return 'https://public-api.wordpress.com/oauth2/token';
40
    }
41
42
    /**
43
     * {@inheritdoc}
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
            $headers['Authorization'] = "Bearer {$accessToken->getToken()}";
57
        }
58 3
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 3
    public function getIdentity(AccessTokenInterface $accessToken)
64
    {
65 3
        $response = $this->request('GET', 'me/', [], $accessToken);
66
67 1
        $hydrator = new ArrayHydrator([
68 1
            'ID' => 'id',
69
            'avatar_URL' => 'pictureURL',
70
        ]);
71
72 1
        return $hydrator->hydrate(new User(), $response);
73
    }
74
}
75