Issues (30)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

MaikuroDistributedConfigurationExtension.php (10 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the distributed-configuration-bundle package
5
 *
6
 * Copyright (c) 2016 Guillaume Cavana
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * Feel free to edit as you please, and have fun.
12
 *
13
 * @author Guillaume Cavana <[email protected]>
14
 */
15
16
namespace Maikuro\DistributedConfigurationBundle\DependencyInjection;
17
18
use Symfony\Component\Config\Definition\Processor;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Definition;
21
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
22
use Symfony\Component\DependencyInjection\Reference;
23
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
24
25
class MaikuroDistributedConfigurationExtension extends Extension
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function load(array $configs, ContainerBuilder $container)
31
    {
32
        $processor = new Processor();
33
        $configuration = new Configuration();
34
        $config = $processor->processConfiguration($configuration, $configs);
35
36
        $this->loadStoreHandler($container, $config);
37
    }
38
39
    /**
40
     * loadStoreHandler.
41
     *
42
     * @param ContainerBuilder $container
43
     * @param array            $config
44
     */
45
    private function loadStoreHandler(ContainerBuilder $container, array $config)
46
    {
47
        $storeHandlerDef = new Definition('Maikuro\DistributedConfigurationBundle\Handler\StoreHandler');
48
        $storeDef = $this->loadStore($container, $config['store']);
49
        if (null === $storeDef) {
50
            throw new InvalidArgumentException('No store found');
51
        }
52
        $storeHandlerDef->addArgument($storeDef);
53
        //Enabled caching
54
        if ($config['cache']['enabled']) {
55
            if (null === $config['cache']['service_id']) {
56
                throw new InvalidArgumentException(
57
                    'You need to install DoctrineCacheBundle and configure it to use cache feature'
58
                );
59
            }
60
            $cachingDecoratorDef = new Definition('Webmozart\KeyValueStore\Decorator\CachingDecorator',
61
                [$storeDef, new Reference($config['cache']['service_id'])]
62
            );
63
            $storeHandlerDef->replaceArgument(0, $cachingDecoratorDef);
64
        }
65
        $container->setDefinition('maikuro_distributed_configuration.store_handler', $storeHandlerDef);
66
    }
67
68
    private function loadStore(ContainerBuilder $container, array $config)
69
    {
70
        switch ($config['type']) {
71
            case 'redis':
72
                return $this->loadRedisStore($container, $config);
73
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
74
            case 'predis':
75
                return $this->loadPredisStore($container, $config);
76
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
77
            case 'dbal':
78
                return $this->loadDbalStore($container, $config);
79
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
80
            case 'json':
81
                return $this->loadJsonStore($container, $config);
82
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
83
            default:
84
                return;
85
                break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
86
        }
87
    }
88
89
    private function loadRedisStore(ContainerBuilder $container, array $config)
90
    {
91
        $redisStoreDef = new Definition('Webmozart\KeyValueStore\PhpRedisStore');
92
93
        if (isset($config['store']['connection_id'])) {
94
            $redisStoreDef->addArgument(new Reference($config['connection_id']));
95
        } else {
96
            $host = $config['host'];
97
            $port = $config['port'];
98
            $connId = 'maikuro_distributed_configuration.redis.connection';
99
            $connDef = new Definition('Redis');
100
            $connParams = array($host, $port);
101
            if (isset($config['timeout'])) {
102
                $connParams[] = $config['timeout'];
103
            }
104
            $connMethod = 'connect';
105
            if (isset($config['persistent']) && $config['persistent']) {
106
                $connMethod = 'pconnect';
107
            }
108
            $connDef->setPublic(false);
109
            $connDef->addMethodCall($connMethod, $connParams);
110 View Code Duplication
            if (isset($config['password'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
111
                $password = $config['password'];
112
                $connDef->addMethodCall('auth', array($password));
113
            }
114 View Code Duplication
            if (isset($config['database'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
115
                $database = (int) $config['database'];
116
                $connDef->addMethodCall('select', array($database));
117
            }
118
            $container->setDefinition($connId, $connDef);
119
120
            $redisStoreDef->addArgument(new Reference($connId));
121
        }
122
123
        return $redisStoreDef;
124
    }
125
126
    private function loadPredisStore(ContainerBuilder $container, array $config)
127
    {
128
        $predisStoreDef = new Definition('Webmozart\KeyValueStore\PredisStore');
129
130
        if (isset($config['client_id'])) {
131
            $predisStoreDef->addArgument(new Reference($config['connection_id']));
132
        } else {
133
            $parameters = array(
134
                'scheme' => $config['scheme'],
135
                'host' => $config['host'],
136
                'port' => $config['port'],
137
            );
138
            if ($config['password']) {
139
                $parameters['password'] = $config['password'];
140
            }
141
            if ($config['timeout']) {
142
                $parameters['timeout'] = $config['timeout'];
143
            }
144
            if ($config['database']) {
145
                $parameters['database'] = $config['database'];
146
            }
147
            $options = null;
148
            if (isset($config['options'])) {
149
                $options = $config['options'];
150
            }
151
            $clientId = 'maikuro_distributed_configuration.predis.client';
152
            $clientDef = new Definition('Predis\Client');
153
            $clientDef->addArgument($parameters);
154
            $clientDef->addArgument($options);
155
            $clientDef->setPublic(false);
156
            $container->setDefinition($clientId, $clientDef);
157
158
            $predisStoreDef->addArgument(new Reference($clientId));
159
        }
160
161
        return $predisStoreDef;
162
    }
163
164
    private function loadJsonStore(ContainerBuilder $container, array $config)
0 ignored issues
show
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
165
    {
166
        $jsonStoreDef = new Definition('Webmozart\KeyValueStore\JsonFileStore');
167
        $jsonStoreDef->addArgument($config['json']['path']);
168
169
        return $jsonStoreDef;
170
    }
171
172
    private function loadDbalStore(ContainerBuilder $container, array $config)
0 ignored issues
show
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
173
    {
174
        $dbalStoreDef = new Definition('Webmozart\KeyValueStore\DbalStore');
175
176
        if (!isset($config['connection_id'])) {
177
            throw new InvalidArgumentException('No dbal connection configured');
178
        }
179
180
        $dbalStoreDef->addArgument(new Reference($config['connection_id']), $config['table_name']);
0 ignored issues
show
The call to Definition::addArgument() has too many arguments starting with $config['table_name'].

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...
181
182
        return $dbalStoreDef;
183
    }
184
}
185