Passed
Branch master (c65ffc)
by Dāvis
03:08
created

GoogleOAuth2Client   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B redirect() 0 17 5
1
<?php
2
3
namespace Sludio\HelperBundle\Oauth\Client\Client;
4
5
use Sludio\HelperBundle\Oauth\Client\OAuth2Client;
6
use Symfony\Component\HttpFoundation\RedirectResponse;
7
8
class GoogleOAuth2Client extends OAuth2Client
9
{
10
    protected $isStateless = false;
11
12
    public function redirect(array $scopes = [], array $options = [], $state = null)
13
    {
14
        if (!empty($scopes)) {
15
            $options['scope'] = $scopes;
16
        }
17
18
        if (!$this->isStateless) {
19
            $this->getSession()->set(self::OAUTH2_SESSION_STATE_KEY, $state ?: $this->provider->getState());
20
            if ($state) {
21
                $this->provider->setState($state);
22
            }
23
        }
24
25
        $options['state'] = $state;
26
        $url = $this->provider->getAuthorizationUrl($options);
27
28
        return new RedirectResponse($url);
29
    }
30
}
31