Completed
Pull Request — master (#8)
by
unknown
02:18
created

Configuration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 97.62%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 67
ccs 41
cts 42
cp 0.9762
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 38 1
A loadConfig() 0 14 2
1
<?php
2
3
/**
4
 * This file is part of the Mediapart Selligent Client API
5
 *
6
 * CC BY-NC-SA <https://github.com/mediapart/selligent>
7
 *
8
 * For the full license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mediapart\Selligent;
13
14
use Symfony\Component\Config\Definition\ConfigurationInterface;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Yaml\Yaml;
17
use Symfony\Component\Config\Definition\Processor;
18
19
use Psr\Log\LoggerInterface;
20
21
/**
22
 * Class Configuration
23
 * @package Mediapart\Selligent
24
 */
25
class Configuration implements ConfigurationInterface
26
{
27
28
    /**
29
     * Define configTree
30
     * @return TreeBuilder
31
     */
32 2
    public function getConfigTreeBuilder()
33
    {
34 2
        $treeBuilder = new TreeBuilder();
35 2
        $rootNode = $treeBuilder->root('selligent');
36
37
        $rootNode
38 2
          ->children()
39 2
            ->scalarNode('login')
40 2
                ->isRequired()
41 2
                ->cannotBeEmpty()
42 2
            ->end()
43 2
            ->scalarNode('password')
44 2
              ->isRequired()
45 2
              ->cannotBeEmpty()
46 2
            ->end()
47 2
            ->scalarNode('namespace')
48 2
                ->defaultValue('http://tempuri.org/')
49 2
            ->end()
50 2
            ->scalarNode('wsdl')
51 2
              ->isRequired()
52 2
              ->cannotBeEmpty()
53 2
            ->end()
54 2
            ->scalarNode('list')
55 2
                ->isRequired()
56 2
            ->end()
57 2
            ->arrayNode('options')
58 2
                ->children()
59 2
                    ->arrayNode('classmap')
60 2
                        ->isRequired()
61 2
                        ->prototype('scalar')
62 2
                    ->end()
63 2
                ->end()
64 2
            ->end()
65 2
          ->end()
66
        ;
67
68 2
        return $treeBuilder;
69
    }
70
71
    /**
72
     * load, validate and return configuration
73
     * @param string $configFile
74
     * @return array
75
     */
76 2
    public function loadConfig($configFile)
77 1
    {
78 2
        if (!empty($configFile)) {
79 2
            $config = Yaml::parse($configFile);
80
81 2
            $processor = new Processor();
82 2
            $processedConfiguration = $processor->processConfiguration(
83 2
              new Configuration(),
84
              $config
85 2
            );
86
87 1
            return $processedConfiguration;
88
        }
89
    }
90
91
}
92