Completed
Push — master ( c90f48...d51382 )
by Robert
07:03 queued 51s
created

MediaMonksRestApiExtension::getDebug()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 10
ccs 5
cts 6
cp 0.8333
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
crap 3.0416
1
<?php
2
3
namespace MediaMonks\RestApiBundle\DependencyInjection;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
8
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
9
use Symfony\Component\DependencyInjection\Loader;
10
11
/**
12
 * This is the class that loads and manages your bundle configuration.
13
 *
14
 * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
15
 */
16
class MediaMonksRestApiExtension extends Extension implements ExtensionInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21 3
    public function load(array $configs, ContainerBuilder $container)
22
    {
23 3
        $config = $this->processConfiguration(new Configuration(), $configs);
24
25 3
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
26 3
        $loader->load('services.xml');
27
28 3
        $container->getDefinition('mediamonks_rest_api.request_matcher')
29 3
            ->replaceArgument(0, $config['request_matcher']['whitelist']);
30 3
        $container->getDefinition('mediamonks_rest_api.request_matcher')
31 3
            ->replaceArgument(1, $config['request_matcher']['blacklist']);
32
33 3
        $container->getDefinition('mediamonks_rest_api.request_transformer')
34 3
            ->replaceArgument(0, $config['output_formats']);
35
36 3
        $container->getDefinition('mediamonks_rest_api.response_transformer')
37 3
            ->replaceArgument(2, [
38 3
                'debug'               => $this->getDebug($config, $container),
39 3
                'post_message_origin' => $config['post_message_origin']
40 3
            ]);
41 3
    }
42
43
    /**
44
     * @return string
45
     */
46 3
    public function getAlias()
47
    {
48 3
        return 'mediamonks_rest_api';
49
    }
50
51
    /**
52
     * @param array $config
53
     * @param ContainerBuilder $container
54
     * @return bool
55
     */
56 3
    public function getDebug(array $config, ContainerBuilder $container)
57
    {
58 3
        if (isset($config['debug'])) {
59
            return $config['debug'];
60
        }
61 3
        if ($container->hasParameter('kernel.debug')) {
62 1
            return $container->getParameter('kernel.debug');
63
        }
64 2
        return false;
65
    }
66
}
67