Issues (6)

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.

src/Utils/CallableResolver.php (4 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 Philae\Utils;
4
5
use League\Container\Container;
6
use League\Container\ContainerAwareInterface;
7
use League\Container\ContainerAwareTrait;
8
use Middlewares\Utils\CallableResolver\CallableResolverInterface;
9
use Middlewares\Utils\CallableResolver\ReflectionResolver;
10
use Middlewares\Utils\CallableResolver\Resolver;
11
use Psr\Container\ContainerInterface;
12
13
/**
14
 * Callable resolver with support for: __invoke magic method, container resolution and reflection resolution.
15
 *
16
 * @method Container|ContainerInterface getContainer()
17
 */
18
class CallableResolver extends Resolver implements CallableResolverInterface, ContainerAwareInterface
19
{
20
    use ContainerAwareTrait;
21
22
    /**
23
     * @var ReflectionResolver
24
     */
25
    private $delegateResolver;
26
27
    /**
28
     * @param CallableResolverInterface|null $delegateResolver
29
     */
30 15
    public function __construct(CallableResolverInterface $delegateResolver = null)
31
    {
32 15
        $this->delegateResolver = $delegateResolver ?: new ReflectionResolver();
0 ignored issues
show
Documentation Bug introduced by
$delegateResolver ?: new...er\ReflectionResolver() is of type object<Middlewares\Utils...lableResolverInterface>, but the property $delegateResolver was declared to be of type object<Middlewares\Utils...ver\ReflectionResolver>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
33 15
    }
34
35 15
    public function resolve($callable, array $args = [])
36
    {
37 15
        $callable = $this->delegateResolver->resolve($this->normalizeCallable($callable, $args), $args);
38
39 15
        if (!$this->getContainer()) {
40
            return $callable;
41
        }
42
43
        // Inflect callable
44 15
        if (is_array($callable) && isset($callable[0]) && ($callable[0] instanceof ContainerAwareInterface)) {
45
            $callable[0]->setContainer($this->getContainer());
0 ignored issues
show
$this->getContainer() of type object<Psr\Container\ContainerInterface> is not a sub-type of object<League\Container\ContainerInterface>. It seems like you assume a child interface of the interface Psr\Container\ContainerInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
46 15
        } elseif ($callable instanceof ContainerAwareInterface) {
47
            $callable->setContainer($this->getContainer());
0 ignored issues
show
$this->getContainer() of type object<Psr\Container\ContainerInterface> is not a sub-type of object<League\Container\ContainerInterface>. It seems like you assume a child interface of the interface Psr\Container\ContainerInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
48
        }
49
50 15
        return $callable;
51
    }
52
53
    /**
54
     * @param mixed $callable
55
     * @param array $args
56
     * @return array|string|mixed
57
     */
58 15
    protected function normalizeCallable($callable, array $args = [])
59
    {
60
        // invokable object
61 15
        if (is_object($callable) && method_exists($callable, '__invoke')) {
62 15
            return $callable;
63
        }
64
65
        // class::method string
66
        if (is_string($callable)) {
67
            // Split ::
68
            $callable = $this->resolveString($callable);
69
        }
70
71
        // function string
72
        if (is_string($callable) && function_exists($callable)) {
73
            return $callable;
74
        }
75
76
        // class string (invokable class)
77
        if (is_string($callable)
78
            && class_exists($callable)
79
            && function_exists($callable . '::__invoke')
80
        ) {
81
            $instance = $this->findInContainer($callable, $args);
82
            if ($instance) {
83
                $callable = $instance;
84
            }
85
86
            return [$callable, '__invoke'];
87
        }
88
89
        // callable array with class and method as strings
90
        if (is_array($callable) && is_string($callable[0]) && class_exists($callable[0])) {
91
            $instance = $this->findInContainer($callable[0], $args);
92
            if ($instance) {
93
                $callable[0] = $instance;
94
            }
95
96
            return $callable;
97
        }
98
99
        return $callable;
100
    }
101
102
    /**
103
     * @param string $className
104
     * @param array $args
105
     * @return bool|mixed
106
     */
107
    protected function findInContainer($className, array $args = [])
108
    {
109
        if ($this->getContainer() && $this->getContainer()->has($className)) {
110
            return $this->getContainer()->get($className, $args);
0 ignored issues
show
The call to ContainerInterface::get() has too many arguments starting with $args.

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...
111
        }
112
113
        return false;
114
    }
115
}
116