Completed
Push — master ( ab8175...d69783 )
by Kamil
15s
created

SyliusFixturesExtension::prepend()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 18
rs 9.4285
cc 3
eloc 10
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\FixturesBundle\DependencyInjection;
13
14
use Symfony\Component\Config\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
17
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
18
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
19
20
/**
21
 * @author Kamil Kokot <[email protected]>
22
 */
23
final class SyliusFixturesExtension extends Extension implements PrependExtensionInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function load(array $config, ContainerBuilder $container)
29
    {
30
        $config = $this->processConfiguration($this->getConfiguration($config, $container), $config);
0 ignored issues
show
Documentation introduced by
$this->getConfiguration($config, $container) is of type object|null, but the function expects a object<Symfony\Component...ConfigurationInterface>.

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...
31
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
32
33
        $loader->load('services.xml');
34
35
        $this->registerSuites($config, $container);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function prepend(ContainerBuilder $container)
42
    {
43
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/driver'));
44
45
        $extensionsNamesToConfigurationFiles = [
46
            'doctrine' => 'doctrine/orm.xml',
47
            'doctrine_mongodb' => 'doctrine/mongodb.xml',
48
            'doctrine_phpcr' => 'doctrine/phpcr.xml',
49
        ];
50
        
51
        foreach ($extensionsNamesToConfigurationFiles as $extensionName => $configurationFile) {
52
            if (!$container->hasExtension($extensionName)) {
53
                continue;
54
            }
55
            
56
            $loader->load($configurationFile);
57
        }
58
    }
59
60
    /**
61
     * @param array $config
62
     * @param ContainerBuilder $container
63
     */
64
    private function registerSuites(array $config, ContainerBuilder $container)
65
    {
66
        $suiteRegistry = $container->findDefinition('sylius_fixtures.suite_registry');
67
        foreach ($config['suites'] as $suiteName => $suiteConfiguration) {
68
            $suiteRegistry->addMethodCall('addSuite', [$suiteName, $suiteConfiguration]);
69
        }
70
    }
71
}
72