Configuration   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 121
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 22 1
A addFacebook() 0 43 1
A addLinkedIn() 0 25 1
A addTwitter() 0 25 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MartinGeorgiev\SocialPostBundle\DependencyInjection;
6
7
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
8
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
9
use Symfony\Component\Config\Definition\ConfigurationInterface;
10
11
/**
12
 * @since 1.0.0
13
 * @license https://opensource.org/licenses/MIT
14
 * @link https://github.com/martin-georgiev/social-post-bundle
15
 */
16
class Configuration implements ConfigurationInterface
17
{
18
    public function getConfigTreeBuilder(): TreeBuilder
19
    {
20
        $treeBuilder = new TreeBuilder('social_post');
21
        $rootNode = $treeBuilder->getRootNode($treeBuilder, 'social_post');
22
23
        $rootNode
24
            ->children()
25
            ->arrayNode('publish_on')
26
            ->requiresAtLeastOneElement()
27
            ->prototype('enum')
28
            ->values(['facebook', 'linkedin', 'twitter'])
29
            ->end()
30
            ->end()
31
            ->end();
32
33
        $providers = $rootNode->children()->arrayNode('providers');
34
        $this->addFacebook($providers);
35
        $this->addLinkedIn($providers);
36
        $this->addTwitter($providers);
37
38
        return $treeBuilder;
39
    }
40
41
    private function addFacebook(ArrayNodeDefinition $node): void
42
    {
43
        $node
44
            ->children()
45
            ->arrayNode('facebook')
46
            ->children()
47
            ->scalarNode('app_id')
48
            ->isRequired()
49
            ->cannotBeEmpty()
50
            ->end()
51
            ->scalarNode('app_secret')
52
            ->isRequired()
53
            ->cannotBeEmpty()
54
            ->end()
55
            ->scalarNode('default_access_token')
56
            ->isRequired()
57
            ->cannotBeEmpty()
58
            ->end()
59
            ->scalarNode('page_id')
60
            ->isRequired()
61
            ->cannotBeEmpty()
62
            ->end()
63
            ->booleanNode('enable_beta_mode')
64
            ->defaultFalse()
65
            ->end()
66
            ->scalarNode('default_graph_version')
67
            ->defaultNull()
68
            ->end()
69
            ->enumNode('persistent_data_handler')
70
            ->values(['session', 'memory'])
71
            ->defaultValue('memory')
72
            ->end()
73
            ->enumNode('pseudo_random_string_generator')
74
            ->values(['mcrypt', 'openssl', 'urandom'])
75
            ->defaultValue('openssl')
76
            ->end()
77
            ->enumNode('http_client_handler')
78
            ->values(['curl', 'stream', 'guzzle'])
79
            ->defaultValue('curl')
80
            ->end()
81
            ->end()
82
            ->end();
83
    }
84
85
    private function addLinkedIn(ArrayNodeDefinition $node): void
86
    {
87
        $node
88
            ->children()
89
            ->arrayNode('linkedin')
90
            ->children()
91
            ->scalarNode('client_id')
92
            ->isRequired()
93
            ->cannotBeEmpty()
94
            ->end()
95
            ->scalarNode('client_secret')
96
            ->isRequired()
97
            ->cannotBeEmpty()
98
            ->end()
99
            ->scalarNode('access_token')
100
            ->isRequired()
101
            ->cannotBeEmpty()
102
            ->end()
103
            ->scalarNode('company_page_id')
104
            ->isRequired()
105
            ->cannotBeEmpty()
106
            ->end()
107
            ->end()
108
            ->end();
109
    }
110
111
    private function addTwitter(ArrayNodeDefinition $node): void
112
    {
113
        $node
114
            ->children()
115
            ->arrayNode('twitter')
116
            ->children()
117
            ->scalarNode('consumer_key')
118
            ->isRequired()
119
            ->cannotBeEmpty()
120
            ->end()
121
            ->scalarNode('consumer_secret')
122
            ->isRequired()
123
            ->cannotBeEmpty()
124
            ->end()
125
            ->scalarNode('access_token')
126
            ->isRequired()
127
            ->cannotBeEmpty()
128
            ->end()
129
            ->scalarNode('access_token_secret')
130
            ->isRequired()
131
            ->cannotBeEmpty()
132
            ->end()
133
            ->end()
134
            ->end();
135
    }
136
}
137