GoogleProviderConfigurator::getProviderClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sludio\HelperBundle\Oauth\Configurator;
4
5
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
6
use Sludio\HelperBundle\Oauth\Client\Provider\Google\Google;
7
use Sludio\HelperBundle\Oauth\Client\Client\GoogleOAuth2Client;
8
9
class GoogleProviderConfigurator implements ProviderConfiguratorInterface
10
{
11
    public function buildConfiguration(NodeBuilder $node)
12
    {
13
        // @formatter:off
14
        $node
15
            ->scalarNode('access_type')
16
                ->defaultValue(null)
17
                ->info('Optional value for sending access_type parameter. More detail: https://developers.google.com/identity/protocols/OpenIDConnect#authenticationuriparameters')
18
            ->end()
19
            ->scalarNode('hosted_domain')
0 ignored issues
show
Bug introduced by
The method scalarNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
            ->/** @scrutinizer ignore-call */ scalarNode('hosted_domain')
Loading history...
20
                ->defaultValue(null)
21
                ->info('Optional value for sending hd parameter. More detail: https://developers.google.com/identity/protocols/OpenIDConnect#hd-param')
22
            ->end()
23
            ->arrayNode('user_fields')
24
                ->prototype('scalar')->end()
25
                ->info('Optional value for additional fields to be requested from the user profile. If set, these values will be included with the defaults. More details: https://developers.google.com/+/web/api/rest/latest/people')
26
            ->end()
27
            ->scalarNode('client_class')
28
                ->info('If you have a sub-class of OAuth2Client you want to use, add it here')
29
                ->defaultValue(GoogleOAuth2Client::class)
30
            ->end()
31
            ->scalarNode('redirect_route')
32
                ->isRequired()
33
                ->cannotBeEmpty()
34
            ->end()
35
            ->arrayNode('provider_options')
36
                ->info('Other options to pass to your provider\'s constructor')
37
                ->prototype('variable')->end()
38
            ->end()
39
        ;
40
        // @formatter:on
41
    }
42
43
    public function getProviderClass(array $config)
44
    {
45
        return Google::class;
46
    }
47
48
    public function getProviderOptions(array $config)
49
    {
50
        $options = [
51
            'clientId' => $config['client_id'],
52
            'clientSecret' => $config['client_secret'],
53
            'redirect_route' => $config['redirect_route'],
54
        ];
55
56
        if ($config['access_type']) {
57
            $options['accessType'] = $config['access_type'];
58
        }
59
60
        if ($config['hosted_domain']) {
61
            $options['hostedDomain'] = $config['hosted_domain'];
62
        }
63
64
        if (!empty($config['user_fields'])) {
65
            $options['userFields'] = $config['user_fields'];
66
        }
67
68
        return array_merge($options, $config['provider_options']);
69
    }
70
71
    public function getProviderDisplayName()
72
    {
73
        return 'Google';
74
    }
75
76
    public function getClientClass(array $config)
77
    {
78
        return $config['client_class'];
79
    }
80
}
81