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

GoogleOAuth2Client::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sludio\HelperBundle\Oauth\Client\Client;
4
5
use Sludio\HelperBundle\Logger\SludioLogger;
6
use Sludio\HelperBundle\Oauth\Client\OAuth2Client;
7
use Symfony\Component\HttpFoundation\RedirectResponse;
8
use Symfony\Component\HttpFoundation\RequestStack;
9
10
class GoogleOAuth2Client extends OAuth2Client
11
{
12
    public function __construct($provider, RequestStack $requestStack, SludioLogger $logger)
13
    {
14
        parent::__construct($provider, $requestStack, $logger);
15
        $this->isStateless = false;
16
    }
17
18
    public function redirect(array $scopes = [], array $options = [], $state = null)
19
    {
20
        if (!empty($scopes)) {
21
            $options['scope'] = $scopes;
22
        }
23
24
        if (!$this->isStateless) {
25
            $this->getSession()->set(self::OAUTH2_SESSION_STATE_KEY, $state ?: $this->provider->getState());
26
            if ($state) {
27
                $this->provider->setState($state);
28
            }
29
        }
30
31
        $options['state'] = $state;
32
        $url = $this->provider->getAuthorizationUrl($options);
33
34
        return new RedirectResponse($url);
35
    }
36
}
37