Issues (37)

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.

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 Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Core\Bus;
12
13
use Cubiche\Core\Bus\Exception\InvalidMiddlewareException;
14
use Cubiche\Core\Bus\Middlewares\MiddlewareInterface;
15
use Cubiche\Core\Collections\ArrayCollection\ArrayList;
16
use Cubiche\Core\Collections\ArrayCollection\SortedArrayHashMap;
17
use Cubiche\Core\Comparable\Comparator;
18
use Cubiche\Core\Comparable\ReverseComparator;
19
use Cubiche\Core\Delegate\Delegate;
20
use Cubiche\Core\Specification\Criteria;
21
22
/**
23
 * Bus class.
24
 *
25
 * @author Ivannis Suárez Jerez <[email protected]>
26
 */
27
class Bus implements BusInterface
28
{
29
    /**
30
     * @var SortedArrayHashMap
31
     */
32
    protected $middlewares;
33
34
    /**
35
     * Bus constructor.
36
     *
37
     * @param MiddlewareInterface[] $middlewares
38
     */
39
    public function __construct(array $middlewares = array())
40
    {
41
        $this->middlewares = new SortedArrayHashMap([], new ReverseComparator(new Comparator()));
42
        foreach ($middlewares as $priority => $middleware) {
43
            if (!$middleware instanceof MiddlewareInterface) {
44
                throw InvalidMiddlewareException::forUnknownValue($middleware);
45
            }
46
47
            $this->addMiddleware($middleware, $priority);
48
        }
49
    }
50
51
    /**
52
     * Adds a middleware to the middleware list. The higher priority value, the earlier a middleware
53
     * will be triggered in the chain (defaults to 0).
54
     *
55
     * @param MiddlewareInterface $middleware
56
     * @param int                 $priority
57
     */
58
    public function addMiddleware(MiddlewareInterface $middleware, $priority = 0)
59
    {
60
        if (!$this->middlewares->containsKey($priority)) {
61
            $this->middlewares->set($priority, new ArrayList());
62
        }
63
64
        /** @var ArrayList $middlewares */
65
        $middlewares = $this->middlewares->get($priority);
66
        if ($middlewares->findOne(Criteria::eq($middleware)) === null) {
67
            $middlewares->add($middleware);
68
        }
69
    }
70
71
    /**
72
     * Add a middleware before a given middleware.
73
     *
74
     * @param MiddlewareInterface $middleware
75
     * @param MiddlewareInterface $target
76
     *
77
     * @throws \InvalidArgumentException
78
     */
79 View Code Duplication
    public function addMiddlewareBefore(MiddlewareInterface $middleware, MiddlewareInterface $target)
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...
80
    {
81
        $priority = $this->middlewarePriority($target);
82
        if ($priority === null) {
83
            throw new \InvalidArgumentException(
84
                sprintf(
85
                    'There is not a middleware of type %s registered.',
86
                    get_class($target)
87
                )
88
            );
89
        }
90
91
        $this->addMiddleware($middleware, $priority + 1);
92
    }
93
94
    /**
95
     * Add a middleware before a given middleware.
96
     *
97
     * @param MiddlewareInterface $middleware
98
     * @param MiddlewareInterface $target
99
     *
100
     * @throws \InvalidArgumentException
101
     */
102 View Code Duplication
    public function addMiddlewareAfter(MiddlewareInterface $middleware, MiddlewareInterface $target)
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...
103
    {
104
        $priority = $this->middlewarePriority($target);
105
        if ($priority === null) {
106
            throw new \InvalidArgumentException(
107
                sprintf(
108
                    'There is not a middleware of type %s registered.',
109
                    get_class($target)
110
                )
111
            );
112
        }
113
114
        $this->addMiddleware($middleware, $priority - 1);
115
    }
116
117
    /**
118
     * @param MiddlewareInterface $middleware
119
     *
120
     * @return int|null
121
     */
122
    protected function middlewarePriority(MiddlewareInterface $middleware)
123
    {
124
        /** @var ArrayList $collection */
125
        foreach ($this->middlewares as $priority => $collection) {
126
            $targetMiddleware = $collection->findOne(Criteria::eq($middleware));
127
            if ($targetMiddleware !== null) {
128
                return $priority;
129
            }
130
        }
131
132
        return;
133
    }
134
135
    /**
136
     * {@inheritdoc}
137
     */
138
    public function dispatch(MessageInterface $message)
139
    {
140
        $chainedMiddleware = $this->chainedExecution();
141
142
        return $chainedMiddleware($message);
143
    }
144
145
    /**
146
     * @return Delegate
147
     */
148
    private function chainedExecution()
149
    {
150
        $middlewares = [];
151
        foreach ($this->middlewares as $priority => $collection) {
152
            foreach ($collection as $middleware) {
153
                $middlewares[] = $middleware;
154
            }
155
        }
156
157
        $next = Delegate::fromClosure(function ($message) {
158
            // the final middleware return the same message
159
            return $message;
160
        });
161
162
        // reverse iteration over middlewares
163
        /** @var MiddlewareInterface $middleware */
164
        while ($middleware = array_pop($middlewares)) {
165
            $next = Delegate::fromClosure(function ($message) use ($middleware, $next) {
166
                return $middleware->handle($message, $next);
167
            });
168
        }
169
170
        return $next;
171
    }
172
}
173