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

Steam::getBaseUri()   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\OpenID\Provider;
9
10
use SocialConnect\Common\ArrayHydrator;
11
use SocialConnect\Provider\AccessTokenInterface;
12
use SocialConnect\Common\Entity\User;
13
14
class Steam extends \SocialConnect\OpenID\AbstractProvider
15
{
16
    const NAME = 'steam';
17
18
    /**
19
     * {@inheritdoc}
20
     */
21 3
    public function getOpenIdUrl()
22
    {
23 3
        return 'https://steamcommunity.com/openid/id';
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 2
    public function getBaseUri()
30
    {
31 2
        return 'https://api.steampowered.com/';
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 3
    public function getName()
38
    {
39 3
        return self::NAME;
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     */
45 2
    protected function parseUserIdFromIdentity($identity): string
46
    {
47 2
        preg_match(
48 2
            '/7[0-9]{15,25}/',
49
            $identity,
50
            $matches
51
        );
52
53 2
        return (string) $matches[0];
54
    }
55
56
    /**
57
     * {@inheritDoc}
58
     */
59 1
    public function prepareRequest(string $method, string $uri, array &$headers, array &$query, AccessTokenInterface $accessToken = null): void
60
    {
61 1
        $query['key'] = $this->consumer->getKey();
62 1
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 1
    public function getIdentity(AccessTokenInterface $accessToken)
68
    {
69
        $query = [
70 1
            'steamids' => $accessToken->getUserId()
71
        ];
72
73 1
        $response = $this->request('GET', 'ISteamUser/GetPlayerSummaries/v0002/', $query, $accessToken);
74
75 1
        $hydrator = new ArrayHydrator([
76 1
            'steamid' => 'id',
77
            'personaname' => 'username',
78
            'realname' => 'fullname'
79
        ]);
80
81 1
        return $hydrator->hydrate(new User(), $response['response']['players'][0]);
82
    }
83
}
84