Passed
Push — master ( 3948f8...d3c224 )
by Dāvis
07:09
created

FacebookOAuthClient   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
B redirect() 0 17 5
A __construct() 0 4 1
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
use Symfony\Component\HttpFoundation\RequestStack;
8
9
class FacebookOAuthClient extends OAuth2Client
10
{
11
    public function __construct($provider, RequestStack $requestStack)
12
    {
13
        parent::__construct($provider, $requestStack);
14
        $this->setAsStateless();
15
    }
16
17
    public function redirect(array $scopes = [], array $options = [], $state = null)
18
    {
19
        if (!empty($scopes)) {
20
            $options['scope'] = $scopes;
21
        }
22
23
        if (!$this->isStateless) {
24
            $this->getSession()->set(self::OAUTH2_SESSION_STATE_KEY, $state ?: $this->provider->getState());
25
            if ($state) {
26
                $this->provider->setState($state);
27
            }
28
        }
29
30
        $options['state'] = $state;
31
        $url = $this->provider->getAuthorizationUrl($options);
32
33
        return new RedirectResponse($url);
34
    }
35
}
36