Issues (3)

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.

Builder/ArgumentsBuilder.php (3 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 declare(strict_types=1);
2
3
namespace Phact\Container\Builder;
4
5
use Phact\Container\Exceptions\NotFoundException;
6
use Psr\Container\ContainerInterface;
7
8
class ArgumentsBuilder
9
{
10
    /**
11
     * @var ContainerInterface
12
     */
13
    protected $container;
14
15 48
    public function setContainer(ContainerInterface $container): void
16
    {
17 48
        $this->container = $container;
18 48
    }
19
20
    /**
21
     * Build arguments by dependencies and parameters
22
     *
23
     * @param DependencyInterface[] $dependencies
24
     * @param ParameterInterface[] $parameters
25
     * @return array
26
     * @throws NotFoundException
27
     */
28 41
    public function buildArguments(array $dependencies, array $parameters): array
29
    {
30 41
        $arguments = [];
31 41
        if (count($dependencies) > 0) {
32 33
            $arguments = $this->buildArgumentsFromDependencies($dependencies, $parameters);
33
        } else {
34 10
            foreach ($parameters as $parameter) {
35 1
                $arguments[] = $this->makeArgumentByParameter($parameter);
36
            }
37
        }
38 38
        return $arguments;
39
    }
40
41
    /**
42
     * @param DependencyInterface[] $dependencies
43
     * @param ParameterInterface[] $parameters
44
     * @return array
45
     * @throws NotFoundException
46
     */
47 33
    protected function buildArgumentsFromDependencies(array $dependencies, array $parameters): array
48
    {
49 33
        $arguments = [];
50 33
        $usedParameters = [];
51
52 33
        foreach ($dependencies as $key => $dependency) {
53
            /** @var ParameterInterface $parameter */
54 33
            $parameter = null;
0 ignored issues
show
$parameter is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
55 33
            if (isset($parameters[$key])) {
56 7
                $parameter = $parameters[$key];
57 7
                $usedParameters[] = $key;
58 7
                $arguments[] = $this->makeArgumentByParameter($parameter);
59 26
            } elseif (isset($parameters[$dependency->getName()])) {
60 10
                $parameter = $parameters[$dependency->getName()];
61 10
                $usedParameters[] = $dependency->getName();
62 10
                $arguments[] = $this->makeArgumentByParameter($parameter);
63
            } else {
64 25
                $arguments[] = $this->makeArgumentByDependency($dependency);
65
            }
66
        }
67
68 30
        $arguments = $this->appendUnusedParamsToArguments($parameters, $arguments, $usedParameters);
69
70 30
        return $arguments;
71
    }
72
73
74
    /**
75
     * @param array $parameters
76
     * @param array $usedParameters
77
     * @param array $arguments
78
     * @return array
79
     * @throws NotFoundException
80
     */
81 30
    protected function appendUnusedParamsToArguments(
82
        array $parameters,
83
        array $arguments,
84
        array $usedParameters = []
85
    ): array {
86 30
        foreach ($parameters as $key => $parameter) {
87 16
            if (!in_array($key, $usedParameters, true)) {
88 1
                $arguments[] = $this->makeArgumentByParameter($parameter);
89
            }
90
        }
91 30
        return $arguments;
92
    }
93
94
    /**
95
     * @param ParameterInterface $parameter
96
     * @return mixed
97
     * @throws NotFoundException
98
     */
99 18 View Code Duplication
    protected function makeArgumentByParameter(ParameterInterface $parameter)
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...
100
    {
101 18
        switch ($parameter->getType()) {
102 18
            case ParameterInterface::TYPE_REFERENCE_REQUIRED:
103 3
                return $this->retrieveRequiredDependencyFromContainer($parameter->getValue());
104
105 16
            case ParameterInterface::TYPE_REFERENCE_OPTIONAL:
106 2
                return $this->retrieveOptionalDependencyFromContainer($parameter->getValue());
107
        }
108 14
        return $parameter->getValue();
109
    }
110
111
    /**
112
     * @param DependencyInterface $dependency
113
     * @return mixed
114
     * @throws NotFoundException
115
     */
116 25 View Code Duplication
    protected function makeArgumentByDependency(DependencyInterface $dependency)
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...
117
    {
118 25
        switch ($dependency->getType()) {
119 25
            case DependencyInterface::TYPE_REQUIRED:
120 20
                return $this->retrieveRequiredDependencyFromContainer($dependency->getValue());
121
122 10
            case DependencyInterface::TYPE_OPTIONAL:
123 2
                return $this->retrieveOptionalDependencyFromContainer($dependency->getValue());
124
        }
125 8
        return $dependency->getValue();
126
    }
127
128
    /**
129
     * @param $id
130
     * @return mixed
131
     * @throws NotFoundException
132
     */
133 23
    protected function retrieveRequiredDependencyFromContainer($id)
134
    {
135 23
        if ($this->container && $this->container->has($id)) {
136 21
            return $this->container->get($id);
137
        }
138 2
        throw new NotFoundException("There is no referenced classes of {$id} found");
139
    }
140
141
    /**
142
     * @param $id
143
     * @return mixed
144
     */
145 4
    protected function retrieveOptionalDependencyFromContainer($id)
146
    {
147 4
        if ($this->container && $this->container->has($id)) {
148 2
            return $this->container->get($id);
149
        }
150 2
        return null;
151
    }
152
}
153