Completed
Push — develop ( 098743...5f7eab )
by Raphael De
02:19
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 80
Code Lines 70

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 80
ccs 0
cts 76
cp 0
rs 8.8387
cc 3
eloc 70
nc 1
nop 0
crap 12

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Majora\Bundle\OAuthServerBundle\DependencyInjection;
4
5
use Majora\Component\OAuth\Entity\AccessToken;
6
use Majora\Component\OAuth\Entity\RefreshToken;
7
use Majora\Component\OAuth\Model\AccessTokenInterface;
8
use Majora\Component\OAuth\Model\RefreshTokenInterface;
9
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
10
use Symfony\Component\Config\Definition\ConfigurationInterface;
11
12
/**
13
 * Majora OAuth server bundle semantical configuration class.
14
 */
15
class Configuration implements ConfigurationInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     *
20
     * @see http://symfony.com/doc/current/components/config/definition.html
21
     */
22
    public function getConfigTreeBuilder()
23
    {
24
        $treeBuilder = new TreeBuilder();
25
        $treeBuilder->root('majora_oauth_server')
26
            ->children()
27
                ->scalarNode('secret')
28
                    ->isRequired()
29
                    ->cannotBeEmpty()
30
                ->end()
31
                ->arrayNode('access_token')
32
                    ->addDefaultsIfNotSet()
33
                    ->children()
34
                        ->integerNode('ttl')
35
                            ->defaultValue(AccessTokenInterface::DEFAULT_TTL)
36
                        ->end()
37
                        ->scalarNode('class')
38
                            ->cannotBeEmpty()
39
                            ->defaultValue(AccessToken::class)
40
                            ->validate()
41
                                ->ifTrue(function ($accessTokenClass) {
42
                                    return !(
43
                                        class_exists($accessTokenClass, true)
44
                                        && (new \ReflectionClass($accessTokenClass))
45
                                            ->implementsInterface(AccessTokenInterface::class)
46
                                    );
47
                                })
48
                                ->thenInvalid('Provided access_token configuration has to be a valid class which implements Majora\Component\OAuth\Model\AccessTokenInterface.')
49
                            ->end()
50
                        ->end()
51
                    ->end()
52
                ->end()
53
54
                ->arrayNode('refresh_token')
55
                    ->addDefaultsIfNotSet()
56
                    ->children()
57
                        ->integerNode('ttl')
58
                            ->defaultValue(RefreshTokenInterface::DEFAULT_TTL)
59
                        ->end()
60
                        ->scalarNode('class')
61
                            ->cannotBeEmpty()
62
                            ->defaultValue(RefreshToken::class)
63
                            ->validate()
64
                                ->ifTrue(function ($refreshTokenClass) {
65
                                    return !(
66
                                        class_exists($refreshTokenClass, true)
67
                                        && (new \ReflectionClass($refreshTokenClass))
68
                                        ->implementsInterface(RefreshTokenInterface::class)
69
                                    );
70
                                })
71
                                ->thenInvalid('Provided refresh_token configuration has to be a valid class which implements Majora\Component\OAuth\Model\RefreshTokenInterface.')
72
                            ->end()
73
                        ->end()
74
                        ->scalarNode('loader')
75
                            ->isRequired()
76
                            ->cannotBeEmpty()
77
                        ->end()
78
                    ->end()
79
                ->end()
80
81
                ->arrayNode('application')
82
                    ->children()
83
                        ->scalarNode('loader')
84
                            ->isRequired()
85
                            ->cannotBeEmpty()
86
                        ->end()
87
                    ->end()
88
                ->end()
89
                ->arrayNode('account')
90
                    ->children()
91
                        ->scalarNode('loader')
92
                            ->isRequired()
93
                            ->cannotBeEmpty()
94
                        ->end()
95
                    ->end()
96
                ->end()
97
            ->end()
98
        ;
99
100
        return $treeBuilder;
101
    }
102
}
103