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
Branch develop (1f013c)
by Maximilian
02:16
created

Ma27ApiKeyAuthenticationExtension   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 23
Bugs 4 Features 2
Metric Value
wmc 13
c 23
b 4
f 2
lcom 1
cbo 8
dl 0
loc 105
ccs 55
cts 55
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 18 1
A loadPassword() 0 6 1
A loadServices() 0 6 2
A loadApiKeyPurger() 0 21 4
B overrideServices() 0 19 5
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('ma27_api_key_authentication.property.apiKeyLength', $config['user']['api_key_length']);
31
32 6
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
33 6
        $this->loadPassword($container, $config['user']['password'], $loader);
34 6
        $this->loadServices($loader);
35 6
        $this->loadApiKeyPurger($container, $loader, $config['api_key_purge']);
36 6
        $this->overrideServices($container, $config['services']);
37
38 6
        $container->setParameter('ma27_api_key_authentication.response_values', $config['response']);
39 6
    }
40
41
    /**
42
     * Loads the password strategy.
43
     *
44
     * @param ContainerBuilder      $container
45
     * @param string                $passwordConfig
46
     * @param Loader\YamlFileLoader $loader
47
     */
48 6
    private function loadPassword(ContainerBuilder $container, $passwordConfig, Loader\YamlFileLoader $loader)
49
    {
50 6
        $container->setParameter('ma27_api_key_authentication.password_hashing_service', $passwordConfig['strategy']);
51 6
        $container->setParameter('ma27_api_key_authentication.password_hasher.phpass.iteration_length', 8);
52 6
        $loader->load('hashers.yml');
53 6
    }
54
55
    /**
56
     * Loads all internal services.
57
     *
58
     * @param Loader\YamlFileLoader $loader
59
     */
60 6
    private function loadServices(Loader\YamlFileLoader $loader)
61
    {
62 6
        foreach (array('security_key', 'authentication', 'security', 'annotation') as $file) {
63 6
            $loader->load(sprintf('%s.yml', $file));
64 6
        }
65 6
    }
66
67
    /**
68
     * Loads the purger job command into the container.
69
     *
70
     * @param ContainerBuilder      $container
71
     * @param Loader\YamlFileLoader $loader
72
     * @param string[]              $purgerConfig
73
     */
74 6
    private function loadApiKeyPurger(ContainerBuilder $container, Loader\YamlFileLoader $loader, array $purgerConfig)
75
    {
76 6
        if ($this->isConfigEnabled($container, $purgerConfig)) {
77 2
            $loader->load('session_cleanup.yml');
78
79 2
            if ($purgerConfig['log_state']) {
80 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...
81 1
                $container->setParameter(
82 1
                    'ma27_api_key_authentication.logger',
83 1
                    $purgerConfig['logger_service']
84 1
                );
85
86 1
                $definition = $container->getDefinition('ma27_api_key_authentication.cleanup_command');
87 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...
88 1
            }
89
90 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...
91 2
                $loader->load('last_action_listener.yml');
92 2
            }
93 2
        }
94 6
    }
95
96
    /**
97
     * Processes the service override configuration into the container.
98
     *
99
     * @param ContainerBuilder $container
100
     * @param array            $services
101
     */
102 6
    private function overrideServices(ContainerBuilder $container, array $services)
103
    {
104 6
        $semanticServiceReplacements = array_filter($services);
105 6
        if (!empty($semanticServiceReplacements)) {
106
            $serviceConfig = array(
107 1
                'auth_handler' => 'ma27_api_key_authentication.auth_handler',
108 1
                'key_factory'  => 'ma27_api_key_authentication.key_factory',
109 1
            );
110
111 1
            foreach ($serviceConfig as $configIndex => $replaceableServiceId) {
112 1
                if (!isset($semanticServiceReplacements[$configIndex]) || null === $serviceId = $semanticServiceReplacements[$configIndex]) {
113 1
                    continue;
114
                }
115
116 1
                $container->removeDefinition($replaceableServiceId);
117 1
                $container->setAlias($replaceableServiceId, new Alias($serviceId));
118 1
            }
119 1
        }
120 6
    }
121
}
122