Completed
Push — master ( dc6a94...5d02ae )
by Rafał
09:03
created

SWPCoreExtension::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 10
cts 10
cp 1
rs 9.568
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Core Bundle.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\CoreBundle\DependencyInjection;
16
17
use SWP\Bundle\StorageBundle\DependencyInjection\Extension\Extension;
18
use SWP\Bundle\StorageBundle\Drivers;
19
use Symfony\Component\Config\FileLocator;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
22
use Symfony\Component\DependencyInjection\Loader;
23
24
/**
25
 * This is the class that loads and manages your bundle configuration.
26
 *
27
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
28
 */
29
class SWPCoreExtension extends Extension implements PrependExtensionInterface
30
{
31
    /**
32
     * {@inheritdoc}
33 2
     */
34
    public function load(array $configs, ContainerBuilder $container)
35 2
    {
36 2
        $config = $this->processConfiguration(new Configuration(), $configs);
37 2
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
38 2
        $loader->load('services.yml');
39
        $loader->load('twig.yml');
40 2
        $loader->load('composite_publishing.yml');
41 2
        $loader->load('rules.yml');
42
        $loader->load('form.yml');
43 2
        $loader->load('output_channel_adapter.yml');
44
        $loader->load('websocket.yml');
45 2
        $loader->load('commands.yml');
46 1
        $this->loadDeviceListener($config, $loader);
47
48 2
        $config = $container->resolveEnvPlaceholders($config);
49
50
        if (!empty($config['superdesk_servers'])) {
51
            $container->setParameter('superdesk_servers', $config['superdesk_servers'][0]);
52
        }
53
54
        $this->registerStorage(Drivers::DRIVER_DOCTRINE_ORM, $config['persistence']['orm']['classes'], $container);
55
    }
56
57
    private function loadDeviceListener(array $config, Loader\YamlFileLoader $loader)
58
    {
59
        if ($config['device_listener']['enabled']) {
60
            $loader->load('device_listener.yml');
61
        }
62
    }
63
64
    public function prepend(ContainerBuilder $container): void
65
    {
66
        $config = $container->getExtensionConfig('doctrine_cache');
67
        $config[0]['providers']['main_cache']['type'] = '%env(DOCTRINE_CACHE_DRIVER)%';
68
69
        $config = $container->resolveEnvPlaceholders(
70
            $config,
71
            true
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string|object<Symfony\Co...ncyInjection\true>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
72
        );
73
74
        $container->prependExtensionConfig('doctrine_cache', $config[0]);
75
76
        $fosHttpCacheConfig = [
77
            'debug' => [
78
                'enabled' => true,
79
            ],
80
        ];
81
82
        $fosHttpCacheConfig['proxy_client']['varnish']['http']['servers'] = '%env(json:resolve:CACHE_SERVERS)%';
83
        $fosHttpCacheConfig = $container->resolveEnvPlaceholders(
84
            $fosHttpCacheConfig,
85
            true
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string|object<Symfony\Co...ncyInjection\true>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
86
        );
87
88
        $container->prependExtensionConfig('fos_http_cache', $fosHttpCacheConfig);
89
    }
90
}
91