Passed
Push — master ( eb2b9c...2ce42f )
by Dāvis
05:18 queued 02:31
created

BaseProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRedirectUri() 0 3 1
A setState() 0 3 1
A __construct() 0 5 1
A getAccessToken() 0 20 4
1
<?php
2
3
namespace Sludio\HelperBundle\Oauth\Client\Provider;
4
5
use League\OAuth2\Client\Provider\AbstractProvider;
6
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
7
use League\OAuth2\Client\Token\AccessToken;
8
9
abstract class BaseProvider extends AbstractProvider
10
{
11
    public $generator;
12
13
    public function __construct(array $options = [], array $collaborators = [], $generator = null)
14
    {
15
        $this->generator = $generator;
16
17
        parent::__construct($options, $collaborators);
18
    }
19
20
    public function getRedirectUri()
21
    {
22
        return $this->redirectUri;
23
    }
24
25
    /**
26
     * Requests an access token using a specified grant and option set.
27
     *
28
     * @param  mixed $grant
29
     * @param  array $options
30
     *
31
     * @param array  $attributes
32
     *
33
     * @return AccessToken
34
     */
35
    public function getAccessToken($grant, array $options = [], array $attributes = [])
36
    {
37
        $grant = $this->verifyGrant($grant);
38
39
        $redirectUri = null;
40
        if (!empty($attributes) && $this->generator) {
41
            $redirectUri = $this->generator->generate($attributes['_route'], $attributes['_route_params'], UrlGeneratorInterface::ABSOLUTE_URL);
42
        }
43
44
        $params = [
45
            'client_id' => $this->clientId,
46
            'client_secret' => $this->clientSecret,
47
            'redirect_uri' => $redirectUri ?: $this->redirectUri,
48
        ];
49
50
        $params = $grant->prepareRequestParameters($params, $options);
51
        $request = $this->getAccessTokenRequest($params);
52
        $response = $this->getParsedResponse($request);
53
        $prepared = $this->prepareAccessTokenResponse($response);
54
        return $this->createAccessToken($prepared, $grant);
55
    }
56
57
    public function setState($state = null)
58
    {
59
        $this->state = $state;
60
    }
61
}
62