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

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 32
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 32
cts 32
cp 1
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 33
nc 1
nop 0
crap 1
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
20
/**
21
 * Class Configuration
22
 * @package Mediapart\Selligent
23
 */
24
class Configuration implements ConfigurationInterface
25
{
26
    /**
27
     * Define configTree
28
     * @return TreeBuilder
29
     */
30 1
    public function getConfigTreeBuilder()
31
    {
32 1
        $treeBuilder = new TreeBuilder();
33 1
        $rootNode = $treeBuilder->root('selligent');
34
35
        $rootNode
36 1
          ->children()
37 1
            ->scalarNode('login')
38 1
                ->isRequired()
39 1
                ->cannotBeEmpty()
40 1
            ->end()
41 1
            ->scalarNode('password')
42 1
              ->isRequired()
43 1
              ->cannotBeEmpty()
44 1
            ->end()
45 1
            ->scalarNode('namespace')
46 1
                ->defaultValue('http://tempuri.org/')
47 1
            ->end()
48 1
            ->scalarNode('wsdl')
49 1
              ->isRequired()
50 1
              ->cannotBeEmpty()
51 1
            ->end()
52 1
            ->scalarNode('list')
53 1
                ->isRequired()
54 1
            ->end()
55 1
            ->arrayNode('options')
56 1
                ->children()
57 1
                    ->arrayNode('classmap')
58 1
                        ->isRequired()
59 1
                        ->prototype('scalar')
60 1
                    ->end()
61 1
                ->end()
62 1
            ->end()
63 1
          ->end()
64
        ;
65
66 1
        return $treeBuilder;
67
    }
68
69
    /**
70
     * load, validate and return configuration
71
     * @param string $configFile
72
     * @return array
73
     */
74 1
    public function loadConfig($configFile)
75
    {
76 1
        if (!empty($configFile)) {
77 1
            $config = Yaml::parse($configFile);
78 1
            $processor = new Processor();
79
80
            try {
81 1
                $processedConfiguration = $processor->processConfiguration(
82 1
                  new Configuration(),
83
                  $config
84 1
                );
85
86
                return $processedConfiguration;
87 1
            } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class Mediapart\Selligent\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
88
                echo $e->getMessage() . PHP_EOL;
89
            }
90
        }
91
    }
92
}
93