GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 6576e7...e3f776 )
by Théo
08:52
created

HautelookAliceExtension::setCommandFactory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Hautelook\AliceBundle package.
5
 *
6
 * (c) Baldur Rensch <[email protected]>
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 Hautelook\AliceBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Definition;
18
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
19
use Symfony\Component\DependencyInjection\Loader;
20
use Symfony\Component\DependencyInjection\Reference;
21
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
22
23
/**
24
 * The extension of this bundle.
25
 *
26
 * @author Baldur Rensch <[email protected]>
27
 */
28
class HautelookAliceExtension extends Extension implements PrependExtensionInterface
29
{
30
    /**
31
     * @var array
32
     */
33
    private $extensions = [];
34
35
    /**
36
     * {@inheritdoc}
37
     *
38
     * Gets Doctrine extensions.
39
     */
40 27
    public function prepend(ContainerBuilder $container)
41
    {
42 27
        $this->extensions[Configuration::ORM_DRIVER] = $container->getExtensionConfig('doctrine');
43 27
        $this->extensions[Configuration::MONGODB_DRIVER] = $container->getExtensionConfig('doctrine_mongodb');
44 27
        $this->extensions[Configuration::PHPCR_DRIVER] = $container->getExtensionConfig('doctrine_phpcr');
45 27
    }
46
47
    /**
48
     * {@inheritdoc}
49
     *
50
     * @throws InvalidConfigurationException
51
     */
52 27
    public function load(array $configs, ContainerBuilder $container)
53
    {
54 27
        $configuration = new Configuration();
55 27
        $config = $this->processConfiguration($configuration, $configs);
56
57 24
        foreach ($config as $key => $value) {
58 24
            $container->setParameter($this->getAlias().'.'.$key, $value);
59 24
        }
60
61 24
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
62 24
        $loader->load('services.xml');
63
64
        // Deprecated factory methods handling.
65
        // To be removed and set directly on config file when bumping Symfony requirements to >=2.6
66 24
        $aliceFakerDefinition = $container->getDefinition('hautelook_alice.faker');
67 24
        if (method_exists($aliceFakerDefinition, 'setFactory')) {
68 8
            $aliceFakerDefinition->setFactory(['Faker\Factory', 'create']);
69 8
        } else {
70 16
            $aliceFakerDefinition->setFactoryClass('Faker\Factory');
0 ignored issues
show
Bug introduced by
The method setFactoryClass() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean setFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
71 16
            $aliceFakerDefinition->setFactoryMethod('create');
0 ignored issues
show
Bug introduced by
The method setFactoryMethod() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean setFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
72
        }
73
74 24
        foreach ($config['db_drivers'] as $driver => $isEnabled) {
75 24
            if (true === $isEnabled
76 24
                || (null === $isEnabled && true === $this->isExtensionEnabled($driver))
77 24
            ) {
78 15
                $loader->load(sprintf('%s.xml', $driver));
79
80 15
                if ('orm' === $driver) {
81 15
                    $this->setCommandFactory($container->getDefinition('hautelook_alice.doctrine.command.deprecated_load_command'));
82 15
                    $this->setCommandFactory($container->getDefinition('hautelook_alice.doctrine.command.load_command'));
83 15
                } else {
84 15
                    $this->setCommandFactory($container->getDefinition(sprintf('hautelook_alice.doctrine.%s.command.load_command', $driver)));
85
                }
86 15
            }
87 24
        }
88
89 24
        $container->getDefinition('hautelook_alice.alice.fixtures.loader')
90 24
            ->replaceArgument(3, $container->getParameterBag()->all());
91 24
    }
92
93 15
    private function setCommandFactory(Definition $commandDefinition)
94
    {
95
        // Deprecated factory methods handling.
96
        // To be removed and set directly on config file when bumping Symfony requirements to >=2.6
97 15
        if (method_exists($commandDefinition, 'setFactory')) {
98 5
            $commandDefinition->setFactory([new Reference('hautelook_alice.doctrine.command_factory'), 'createCommand']);
99 5
        } else {
100 10
            $commandDefinition->setFactoryService('hautelook_alice.doctrine.command_factory');
0 ignored issues
show
Bug introduced by
The method setFactoryService() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean setFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
101 10
            $commandDefinition->setFactoryMethod('createCommand');
0 ignored issues
show
Bug introduced by
The method setFactoryMethod() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean setFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
102
        }
103 15
    }
104
105
    /**
106
     * @param string $driver
107
     *
108
     * @return bool
109
     */
110 9
    private function isExtensionEnabled($driver)
111
    {
112 9
        return !empty($this->extensions[$driver]);
113
    }
114
}
115