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 ( cb7f05...c88989 )
by Maximilian
09:13
created

overrideServices()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 9.2
cc 4
eloc 9
nc 3
nop 2
crap 4
1
<?php
2
3
namespace Ma27\ApiKeyAuthenticationBundle\DependencyInjection;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\Alias;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
10
11
/**
12
 * This is the class that loads and manages your bundle configuration.
13
 *
14
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
15
 */
16
class Ma27ApiKeyAuthenticationExtension extends Extension
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21 7
    public function load(array $configs, ContainerBuilder $container)
22
    {
23 7
        $configuration = new Configuration();
24 7
        $config = $this->processConfiguration($configuration, $configs);
25
26 7
        $container->setParameter('ma27_api_key_authentication.key_header', $config['key_header']);
27 7
        $container->setParameter('ma27_api_key_authentication.response_values', $config['response']);
28
29 7
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
30
31 7
        $this->loadCore($container, $loader, $config['user']);
32 7
        $this->loadServices($loader);
33
34 7
        if ($this->isConfigEnabled($container, $config['api_key_purge'])) {
35 2
            $this->loadApiKeyPurger($container, $loader, $config['api_key_purge']);
36
        }
37
38 7
        $services = array_filter($config['services']);
39 7
        if (!empty($services)) {
40 1
            $this->overrideServices($container, $services);
41
        }
42
43 7
        if ($config['user']['metadata_cache']) {
44 2
            $cacheDir = $container->getParameter('kernel.cache_dir');
45
46 2
            $container->getDefinition('ma27_api_key_authentication.class_metadata_factory')
47 2
                ->replaceArgument(3, sprintf('%s/ma27_api_key_authentication/metadata_dump', $cacheDir));
48
        }
49 7
    }
50
51
    /**
52
     * Loads the user and core related stuff of the bundle.
53
     *
54
     * @param ContainerBuilder      $container
55
     * @param Loader\YamlFileLoader $loader
56
     * @param array                 $config
57
     */
58 7
    private function loadCore(ContainerBuilder $container, Loader\YamlFileLoader $loader, $config)
59
    {
60 7
        $isCacheEnabled = $config['metadata_cache'];
61
62 7
        $container->setParameter('ma27_api_key_authentication.model_name', $config['model_name']);
63 7
        $container->setParameter('ma27_api_key_authentication.object_manager', $config['object_manager']);
64 7
        $container->setParameter('ma27_api_key_authentication.property.apiKeyLength', $config['api_key_length']);
65 7
        $container->setParameter('ma27_api_key_authentication.metadata_cache_enabled', $isCacheEnabled);
66
67 7
        if ($isCacheEnabled) {
68 2
            $loader->load('metadata_cache_warmer.yml');
69
        }
70
71 7
        $this->loadPassword($container, $config['password'], $loader);
72 7
    }
73
74
    /**
75
     * Loads the password strategy.
76
     *
77
     * @param ContainerBuilder      $container
78
     * @param string                $passwordConfig
79
     * @param Loader\YamlFileLoader $loader
80
     */
81 7
    private function loadPassword(ContainerBuilder $container, $passwordConfig, Loader\YamlFileLoader $loader)
82
    {
83 7
        $container->setParameter('ma27_api_key_authentication.password_hashing_service', $passwordConfig['strategy']);
84 7
        $container->setParameter('ma27_api_key_authentication.password_hasher.phpass.iteration_length', 8);
85 7
        $container->setParameter('ma27_api_key_authentication.password_hasher.php55.cost', 12);
86
87 7
        $loader->load('hashers.yml');
88 7
    }
89
90
    /**
91
     * Loads all internal services.
92
     *
93
     * @param Loader\YamlFileLoader $loader
94
     */
95 7
    private function loadServices(Loader\YamlFileLoader $loader)
96
    {
97 7
        foreach (array('security_key', 'authentication', 'security', 'annotation') as $file) {
98 7
            $loader->load(sprintf('%s.yml', $file));
99
        }
100 7
    }
101
102
    /**
103
     * Loads the purger job command into the container.
104
     *
105
     * @param ContainerBuilder      $container
106
     * @param Loader\YamlFileLoader $loader
107
     * @param string[]              $purgerConfig
108
     */
109 2
    private function loadApiKeyPurger(ContainerBuilder $container, Loader\YamlFileLoader $loader, array $purgerConfig)
110
    {
111 2
        $container->setParameter('ma27_api_key_authentication.cleanup_command.date_time_rule', $purgerConfig['outdated_rule']);
112 2
        $loader->load('session_cleanup.yml');
113
114 2
        if ($this->isConfigEnabled($container, $purgerConfig['last_action_listener'])) {
0 ignored issues
show
Documentation introduced by
$purgerConfig['last_action_listener'] is of type string, but the function expects a array.

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...
115 2
            $loader->load('last_action_listener.yml');
116
        }
117 2
    }
118
119
    /**
120
     * Processes the service override configuration into the container.
121
     *
122
     * @param ContainerBuilder $container
123
     * @param array            $services
124
     */
125 1
    private function overrideServices(ContainerBuilder $container, array $services)
126
    {
127
        $serviceConfig = array(
128 1
            'auth_handler' => 'ma27_api_key_authentication.auth_handler',
129
            'key_factory'  => 'ma27_api_key_authentication.key_factory',
130
        );
131
132 1
        foreach ($serviceConfig as $configIndex => $replaceableServiceId) {
133 1
            if (!isset($services[$configIndex]) || null === $serviceId = $services[$configIndex]) {
134 1
                continue;
135
            }
136
137 1
            $container->removeDefinition($replaceableServiceId);
138 1
            $container->setAlias($replaceableServiceId, new Alias($serviceId));
139
        }
140 1
    }
141
}
142