Issues (9)

Security Analysis    no request data  

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.

src/League/ServiceServiceProvider.php (2 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
namespace TomPHP\ContainerConfigurator\League;
4
5
use League\Container\Definition\ClassDefinition;
6
use League\Container\ServiceProvider\AbstractServiceProvider;
7
use TomPHP\ContainerConfigurator\Configurator;
8
use TomPHP\ContainerConfigurator\Exception\NotClassDefinitionException;
9
use TomPHP\ContainerConfigurator\ServiceConfig;
10
use TomPHP\ContainerConfigurator\ServiceDefinition;
11
12
/**
13
 * @internal
14
 */
15
final class ServiceServiceProvider extends AbstractServiceProvider
16
{
17
    /**
18
     * @var array
19
     */
20
    private $config;
21
22
    /**
23
     * @param ServiceConfig $config
24
     */
25
    public function __construct(ServiceConfig $config)
26
    {
27
        $this->config   = $config;
0 ignored issues
show
Documentation Bug introduced by
It seems like $config of type object<TomPHP\ContainerC...igurator\ServiceConfig> is incompatible with the declared type array of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
28
        $this->provides = $config->getKeys();
29
    }
30
31
    public function register()
32
    {
33
        foreach ($this->config as $config) {
34
            $this->registerService($config);
35
        }
36
    }
37
38
    /**
39
     * @param ServiceDefinition $definition
40
     *
41
     * @throws NotClassDefinitionException
42
     *
43
     * @return void
44
     */
45
    private function registerService(ServiceDefinition $definition)
46
    {
47
        if ($definition->isFactory()) {
48
            $this->getContainer()->add(
49
                $definition->getName(),
50
                $this->createFactoryFactory($definition),
51
                $definition->isSingleton()
52
            );
53
54
            return;
55
        }
56
57
        if ($definition->isAlias()) {
58
            $this->getContainer()->add(
59
                $definition->getName(),
60
                $this->createAliasFactory($definition)
61
            );
62
63
            return;
64
        }
65
66
        $service = $this->getContainer()->add(
67
            $definition->getName(),
68
            $definition->getClass(),
69
            $definition->isSingleton()
70
        );
71
72
        if (!$service instanceof ClassDefinition) {
73
            throw NotClassDefinitionException::fromServiceName($definition->getName());
74
        }
75
76
        $service->withArguments($this->injectContainer($definition->getArguments()));
77
        $this->addMethodCalls($service, $definition);
78
    }
79
80
    /**
81
     * @param ClassDefinition   $service
82
     * @param ServiceDefinition $definition
83
     */
84
    private function addMethodCalls(ClassDefinition $service, ServiceDefinition $definition)
85
    {
86
        foreach ($definition->getMethods() as $method => $args) {
87
            $service->withMethodCall($method, $this->injectContainer($args));
88
        }
89
    }
90
91
    /**
92
     * @param ServiceDefinition $definition
93
     *
94
     * @return \Closure
95
     */
96
    private function createAliasFactory(ServiceDefinition $definition)
97
    {
98
        return function () use ($definition) {
99
            return $this->getContainer()->get($definition->getClass());
100
        };
101
    }
102
103
    /**
104
     * @param ServiceDefinition $definition
105
     *
106
     * @return \Closure
107
     */
108 View Code Duplication
    private function createFactoryFactory(ServiceDefinition $definition)
0 ignored issues
show
This method seems to be duplicated in 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...
109
    {
110
        return function () use ($definition) {
111
            $className = $definition->getClass();
112
            $factory   = new $className();
113
114
            return $factory(...$this->resolveArguments($definition->getArguments()));
115
        };
116
    }
117
118
    /**
119
     * @param array $arguments
120
     *
121
     * @return array
122
     */
123
    private function injectContainer(array $arguments)
124
    {
125
        return array_map(
126
            function ($argument) {
127
                return ($argument === Configurator::container())
128
                    ? $this->container
129
                    : $argument;
130
            },
131
            $arguments
132
        );
133
    }
134
135
    /**
136
     * @param array $arguments
137
     *
138
     * @return array
139
     */
140
    private function resolveArguments(array $arguments)
141
    {
142
        return array_map(
143
            function ($argument) {
144
                if ($argument === Configurator::container()) {
145
                    return $this->container;
146
                }
147
148
                if ($this->container->has($argument)) {
149
                    return $this->container->get($argument);
150
                }
151
152
                return $argument;
153
            },
154
            $arguments
155
        );
156
    }
157
}
158