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 ( e0afd8...4c7d34 )
by Maximilian
03:31
created

overrideServices()   B

Complexity

Conditions 6
Paths 7

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 6.0359

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 26
ccs 18
cts 20
cp 0.9
rs 8.439
cc 6
eloc 15
nc 7
nop 2
crap 6.0359
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
use Symfony\Component\Validator\Tests\Fixtures\Reference;
11
12
/**
13
 * This is the class that loads and manages your bundle configuration.
14
 *
15
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
16
 */
17
class Ma27ApiKeyAuthenticationExtension extends Extension
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 6
    public function load(array $configs, ContainerBuilder $container)
23
    {
24 6
        $configuration = new Configuration();
25 6
        $config = $this->processConfiguration($configuration, $configs);
26
27 6
        $container->setParameter('ma27_api_key_authentication.key_header', $config['key_header']);
28 6
        $container->setParameter('ma27_api_key_authentication.model_name', $config['user']['model_name']);
29 6
        $container->setParameter('ma27_api_key_authentication.object_manager', $config['user']['object_manager']);
30 6
        $container->setParameter(
31 6
            'ma27_api_key_authentication.property.apiKeyLength',
32 6
            (int) floor($config['user']['api_key_length'] / 2) // TODO to be moved to the `KeyFactory`
33 6
        );
34
35 6
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
36 6
        $this->loadPassword($container, $config['user']['password'], $loader);
37 6
        $this->loadServices($loader);
38 6
        $this->loadApiKeyPurger($container, $loader, $config['api_key_purge']);
39 6
        $this->overrideServices($container, $config['services']);
40
41 6
        $container->setParameter('ma27_api_key_authentication.response_values', $config['response']);
42 6
    }
43
44
    /**
45
     * Loads the password strategy.
46
     *
47
     * @param ContainerBuilder      $container
48
     * @param string                $passwordConfig
49
     * @param Loader\YamlFileLoader $loader
50
     */
51 6
    private function loadPassword(ContainerBuilder $container, $passwordConfig, Loader\YamlFileLoader $loader)
52
    {
53
        // TODO refactor this, the `phpass_iteration_length` is specific for a single strategy and therefore it shouldn't be present in the semantic configuration.
54 6
        $container->setParameter(
55 6
            'ma27_api_key_authentication.password_hasher.phpass.iteration_length',
56 6
            isset($passwordConfig['phpass_iteration_length']) ? $passwordConfig['phpass_iteration_length'] : 8
57 6
        );
58 6
        $loader->load('hashers.yml');
59
60 6
        $container->setParameter(
61 6
            'ma27_api_key_authentication.password_hashing_service',
62 6
            $passwordConfig['strategy']
63 6
        );
64 6
    }
65
66
    /**
67
     * Loads all internal services.
68
     *
69
     * @param Loader\YamlFileLoader $loader
70
     */
71 6
    private function loadServices(Loader\YamlFileLoader $loader)
72
    {
73 6
        foreach (array('security_key', 'authentication', 'security', 'annotation') as $file) {
74 6
            $loader->load(sprintf('%s.yml', $file));
75 6
        }
76 6
    }
77
78
    /**
79
     * Loads the purger job command into the container.
80
     *
81
     * @param ContainerBuilder      $container
82
     * @param Loader\YamlFileLoader $loader
83
     * @param string[]              $purgerConfig
84
     */
85 6
    private function loadApiKeyPurger(ContainerBuilder $container, Loader\YamlFileLoader $loader, array $purgerConfig)
86
    {
87 6
        if ($this->isConfigEnabled($container, $purgerConfig)) {
88 2
            $loader->load('session_cleanup.yml');
89
90 2
            if ($purgerConfig['log_state']) {
91 1
                @trigger_error('The options `api_key_purge.log_state` and the corresponding logger support are deprecated and will be dropped/removed in 2.0!', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
92 1
                $container->setParameter(
93 1
                    'ma27_api_key_authentication.logger',
94 1
                    $purgerConfig['logger_service']
95 1
                );
96
97 1
                $definition = $container->getDefinition('ma27_api_key_authentication.cleanup_command');
98 1
                $definition->addArgument(new Reference($container->getParameter('ma27_api_key_authentication.logger')));
0 ignored issues
show
Unused Code introduced by
The call to Reference::__construct() has too many arguments starting with $container->getParameter...authentication.logger').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
99 1
            }
100
101 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...
102 2
                $loader->load('last_action_listener.yml');
103 2
            }
104 2
        }
105 6
    }
106
107
    /**
108
     * Processes the service override configuration into the container.
109
     *
110
     * @param ContainerBuilder $container
111
     * @param array            $services
112
     */
113 6
    private function overrideServices(ContainerBuilder $container, array $services)
114
    {
115 6
        $semanticServiceReplacements = array_filter($services);
116 6
        if (!empty($semanticServiceReplacements)) {
117
            $serviceConfig = array(
118 1
                'auth_handler'    => 'ma27_api_key_authentication.auth_handler',
119 1
                'key_factory'     => 'ma27_api_key_authentication.key_factory',
120 1
                'password_hasher' => 'ma27_api_key_authentication.password.strategy',
121 1
            );
122
123 1
            if (isset($services['password_hasher'])) {
124
                @trigger_error('The option `services.password_hasher` is deprecated, to be removed in 2.0, create a custom hasher instead!', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
125
            }
126
127 1
            foreach ($serviceConfig as $configIndex => $replaceableServiceId) {
128 1
                if (!isset($semanticServiceReplacements[$configIndex])
129 1
                    || null === $serviceId = $semanticServiceReplacements[$configIndex]
130 1
                ) {
131 1
                    continue;
132
                }
133
134 1
                $container->removeDefinition($replaceableServiceId);
135 1
                $container->setAlias($replaceableServiceId, new Alias($serviceId));
136 1
            }
137 1
        }
138 6
    }
139
}
140