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

Configuration::setLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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
use Psr\Log\LoggerInterface;
20
21
/**
22
 * Class Configuration
23
 * @package Mediapart\Selligent
24
 */
25
class Configuration implements ConfigurationInterface
26
{
27
    /**
28
     * @var LoggerInterface
29
     */
30
    protected $logger = null;
31
32
    /**
33
     * {@inheritDoc}
34
     */
35 1
    public function setLogger(LoggerInterface $logger)
36
    {
37 1
        $this->logger = $logger;
38 1
    }
39
40
    /**
41
     * Define configTree
42
     * @return TreeBuilder
43
     */
44 2
    public function getConfigTreeBuilder()
45
    {
46 2
        $treeBuilder = new TreeBuilder();
47 2
        $rootNode = $treeBuilder->root('selligent');
48
49
        $rootNode
50 2
          ->children()
51 2
            ->scalarNode('login')
52 2
                ->isRequired()
53 2
                ->cannotBeEmpty()
54 2
            ->end()
55 2
            ->scalarNode('password')
56 2
              ->isRequired()
57 2
              ->cannotBeEmpty()
58 2
            ->end()
59 2
            ->scalarNode('namespace')
60 2
                ->defaultValue('http://tempuri.org/')
61 2
            ->end()
62 2
            ->scalarNode('wsdl')
63 2
              ->isRequired()
64 2
              ->cannotBeEmpty()
65 2
            ->end()
66 2
            ->scalarNode('list')
67 2
                ->isRequired()
68 2
            ->end()
69 2
            ->arrayNode('options')
70 2
                ->children()
71 2
                    ->arrayNode('classmap')
72 2
                        ->isRequired()
73 2
                        ->prototype('scalar')
74 2
                    ->end()
75 2
                ->end()
76 2
            ->end()
77 2
          ->end()
78
        ;
79
80 2
        return $treeBuilder;
81
    }
82
83
    /**
84
     * load, validate and return configuration
85
     * @param string $configFile
86
     * @return array
87
     */
88 2
    public function loadConfig($configFile)
89
    {
90 2
        if (!empty($configFile)) {
91 2
            $config = Yaml::parse($configFile);
92
93
            try {
94 2
                $processor = new Processor();
95 2
                $processedConfiguration = $processor->processConfiguration(
96 2
                  new Configuration(),
97
                  $config
98
                );
99
100 1
                return $processedConfiguration;
101 1
            } catch (InvalidConfigurationException $e) {
0 ignored issues
show
Bug introduced by
The class Mediapart\Selligent\InvalidConfigurationException 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...
102
                if ($this->logger) {
103
                    $this->logger->error($e->getMessage());
104
                }
105
            }
106
        }
107
    }
108
109
110
}
111