Passed
Pull Request — master (#190)
by AD
05:46 queued 03:08
created

Meetup   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 66
ccs 17
cts 18
cp 0.9444
rs 10
c 1
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRequestTokenUri() 0 3 1
A getName() 0 3 1
A getBaseUri() 0 3 1
A getAuthorizeUri() 0 3 1
A prepareRequest() 0 6 2
A getIdentity() 0 15 1
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 * @author: Andreas Heigl https://github.com/heiglandreas <[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;
14
15
class Meetup extends \SocialConnect\OAuth2\AbstractProvider
16
{
17
    const NAME = 'meetup';
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 4
    public function getBaseUri()
23
    {
24 4
        return 'https://api.meetup.com/';
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 2
    public function getAuthorizeUri()
31
    {
32 2
        return 'https://secure.meetup.com/oauth2/authorize';
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 2
    public function getRequestTokenUri()
39
    {
40 2
        return 'https://secure.meetup.com/oauth2/access';
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 3
    public function getName()
47
    {
48 3
        return self::NAME;
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54 3
    public function prepareRequest(string $method, string $uri, array &$headers, array &$query, ?AccessTokenInterface $accessToken = null): void
55
    {
56 3
        $query['format'] = 'json';
57
58 3
        if ($accessToken) {
59 3
            $headers['Authorization'] = "Bearer {$accessToken->getToken()}";
60
        }
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 3
    public function getIdentity(AccessTokenInterface $accessToken)
67
    {
68 3
        $response = $this->request('GET', '2/member/self?sign=true&photo-host=public&fields=gender', [], $accessToken);
69
70 1
        $hydrator = new ArrayHydrator([
71
            'id' => 'id',
72
            'username' => 'name',
73
            'fullname' => 'name',
74 1
            'sex' => static function ($value, User $user) {
75
                $user->setSex($value);
76
            },
77
            'photo.photo_link' => 'pictureURL'
78
        ]);
79
80 1
        return $hydrator->hydrate(new User(), $response);
81
    }
82
}
83