FacebookProviderConfigurator::getClientClass()   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\Facebook\Facebook;
7
use Sludio\HelperBundle\Oauth\Client\Client\FacebookOAuthClient;
8
9
class FacebookProviderConfigurator implements ProviderConfiguratorInterface
10
{
11
    public function buildConfiguration(NodeBuilder $node)
12
    {
13
        // @formatter:off
14
        $node
15
            ->scalarNode('graph_api_version')
16
                ->isRequired()
17
                ->defaultValue('v2.8')
18
            ->end()
19
            ->arrayNode('fields')
0 ignored issues
show
Bug introduced by
The method arrayNode() 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 */ arrayNode('fields')
Loading history...
20
                ->beforeNormalization()
21
                    ->ifString()
22
                        ->then(function($v) {
23
                            return preg_split('/\s*,\s*/', $v);
24
                        })
25
                    ->end()
26
                ->prototype('scalar')->end()
27
                ->validate()
28
                    ->ifTrue(function($value) {
29
                        $fields = \explode(';', Facebook::FIELDS);
30
                        foreach ($value as $v) {
31
                            foreach (preg_split('/\s*,\s*/', $v) as $item) {
32
                                if (!\in_array($item, $fields)) {
33
                                    return true;
34
                                }
35
                            }
36
                        }
37
                    })
38
                    ->thenInvalid('Unsupported field. Supported fields: '.Facebook::FIELDS)
39
                ->end()
40
                ->defaultValue([])
41
            ->end()
42
            ->scalarNode('client_class')
43
                ->info('If you have a sub-class of OAuth2Client you want to use, add it here')
44
                ->defaultValue(FacebookOAuthClient::class)
45
            ->end()
46
            ->scalarNode('redirect_route')
47
                ->isRequired()
48
                ->cannotBeEmpty()
49
            ->end()
50
            ->arrayNode('provider_options')
51
                ->info('Other options to pass to your provider\'s constructor')
52
                ->prototype('variable')->end()
53
            ->end()
54
        ;
55
        // @formatter:on
56
    }
57
58
    public function getProviderClass(array $config)
59
    {
60
        return Facebook::class;
61
    }
62
63
    public function getProviderOptions(array $config)
64
    {
65
        return array_merge([
66
            'clientId' => $config['client_id'],
67
            'clientSecret' => $config['client_secret'],
68
            'graphApiVersion' => $config['graph_api_version'],
69
            'redirect_route' => $config['redirect_route'],
70
            'fields' => $config['fields'],
71
        ], $config['provider_options']);
72
    }
73
74
    public function getProviderDisplayName()
75
    {
76
        return 'Facebook';
77
    }
78
79
    public function getClientClass(array $config)
80
    {
81
        return $config['client_class'];
82
    }
83
}
84