Completed
Pull Request — master (#16)
by Yann
13:51
created

YokaiSecurityTokenExtension::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Yokai\SecurityTokenBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Yokai\SecurityTokenBundle\DependencyInjection\Factory\TokenConfigurationFactory;
10
11
/**
12
 * @author Yann Eugoné <[email protected]>
13
 */
14
class YokaiSecurityTokenExtension extends Extension
15
{
16
    /**
17
     * @inheritdoc
18
     */
19 4
    public function load(array $configs, ContainerBuilder $container)
20
    {
21 4
        $config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs);
0 ignored issues
show
Documentation introduced by
$this->getConfiguration($configs, $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...
22
23 4
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
24 4
        $loader->load('services.xml');
25
26 4
        $this->registerTokens($config, $container);
27 4
        $this->registerAliases($config, $container);
28 4
    }
29
30
    /**
31
     * @param array            $config
32
     * @param ContainerBuilder $container
33
     */
34 4
    private function registerTokens(array $config, ContainerBuilder $container)
35
    {
36 4
        foreach ($config['tokens'] as $name => $token) {
37 3
            TokenConfigurationFactory::create(
38
                $name,
39 3
                $token['generator'],
40 3
                $token['duration'],
41 3
                $token['usages'],
42 3
                $token['keep'],
43 3
                $container
44
            );
45
        }
46 4
    }
47
48
    /**
49
     * @param array            $config
50
     * @param ContainerBuilder $container
51
     */
52 4
    private function registerAliases(array $config, ContainerBuilder $container)
53
    {
54 4
        foreach ($config['services'] as $name => $service) {
55 4
            $container->setAlias(sprintf('yokai_security_token.%s', $name), $service);
56
        }
57 4
    }
58
}
59