Issues (7)

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.

Event/EventBus.php (1 issue)

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
12
namespace Cubiche\Core\EventBus\Event;
13
14
use Cubiche\Core\Bus\Bus;
15
use Cubiche\Core\Bus\Exception\NotFoundException;
16
use Cubiche\Core\Bus\MessageInterface;
17
use Cubiche\Core\Bus\Middlewares\Locking\LockingMiddleware;
18
use Cubiche\Core\EventBus\Middlewares\EventDispatcher\EventDispatcherMiddleware;
19
use Cubiche\Core\EventDispatcher\EventDispatcher;
20
21
/**
22
 * EventBus class.
23
 *
24
 * @author Ivannis Suárez Jerez <[email protected]>
25
 */
26
class EventBus extends Bus
27
{
28
    /**
29
     * @var EventDispatcherMiddleware
30
     */
31
    protected $dispatcherMiddleware;
32
33
    /**
34
     * @return EventBus
35
     */
36
    public static function create()
37
    {
38
        return new static([
39
            250 => new LockingMiddleware(),
40
            100 => new EventDispatcherMiddleware(new EventDispatcher()),
41
        ]);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function dispatch(MessageInterface $event)
48
    {
49 View Code Duplication
        if (!$event instanceof EventInterface) {
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...
50
            throw new \InvalidArgumentException(
51
                sprintf(
52
                    'The object must be an instance of %s. Instance of %s given',
53
                    EventInterface::class,
54
                    get_class($event)
55
                )
56
            );
57
        }
58
59
        $this->ensureEventDispatcherMiddleware();
60
61
        parent::dispatch($event);
62
    }
63
64
    /**
65
     * Ensure that exists an dispatcher middleware.
66
     *
67
     * @throws InvalidArgumentException
68
     */
69
    protected function ensureEventDispatcherMiddleware()
70
    {
71
        if ($this->dispatcherMiddleware !== null) {
72
            return;
73
        }
74
75
        foreach ($this->middlewares as $priority => $collection) {
76
            foreach ($collection as $middleware) {
77
                if ($middleware instanceof EventDispatcherMiddleware) {
78
                    $this->dispatcherMiddleware = $middleware;
79
80
                    return;
81
                }
82
            }
83
        }
84
85
        throw NotFoundException::middlewareOfType(EventDispatcherMiddleware::class);
86
    }
87
88
    /**
89
     * @return EventDispatcherMiddleware
90
     */
91
    public function dispatcherMiddleware()
92
    {
93
        $this->ensureEventDispatcherMiddleware();
94
95
        return $this->dispatcherMiddleware;
96
    }
97
98
    /**
99
     * Adds an event listener that listens on the specified events. The higher priority value, the earlier an event
100
     * listener will be triggered in the chain (defaults to 0).
101
     *
102
     * @param string   $eventName
103
     * @param callable $listener
104
     * @param int      $priority
105
     *
106
     * @return $this
107
     */
108
    public function addListener($eventName, callable $listener, $priority = 0)
109
    {
110
        $this->ensureEventDispatcherMiddleware();
111
112
        $this->dispatcherMiddleware->dispatcher()->addListener($eventName, $listener, $priority);
113
    }
114
115
    /**
116
     * Removes an event listener from the specified events.
117
     *
118
     * @param string   $eventName
119
     * @param callable $listener
120
     *
121
     * @return $this
122
     */
123
    public function removeListener($eventName, callable $listener)
124
    {
125
        $this->ensureEventDispatcherMiddleware();
126
127
        $this->dispatcherMiddleware->dispatcher()->removeListener($eventName, $listener);
128
    }
129
130
    /**
131
     * Adds an event subscriber. The subscriber is asked for all the events he is
132
     * interested in and added as a listener for these events.
133
     *
134
     * @param EventSubscriberInterface $subscriber
135
     *
136
     * @return $this
137
     */
138
    public function addSubscriber(EventSubscriberInterface $subscriber)
139
    {
140
        $this->ensureEventDispatcherMiddleware();
141
142
        $this->dispatcherMiddleware->dispatcher()->addSubscriber($subscriber);
143
    }
144
145
    /**
146
     * Removes an event subscriber.
147
     *
148
     * @param EventSubscriberInterface $subscriber
149
     *
150
     * @return $this
151
     */
152
    public function removeSubscriber(EventSubscriberInterface $subscriber)
153
    {
154
        $this->ensureEventDispatcherMiddleware();
155
156
        $this->dispatcherMiddleware->dispatcher()->removeSubscriber($subscriber);
157
    }
158
159
    /**
160
     * Gets the list of event listeners.
161
     *
162
     * @return array
163
     */
164
    public function listeners()
165
    {
166
        $this->ensureEventDispatcherMiddleware();
167
168
        return $this->dispatcherMiddleware->dispatcher()->listeners();
169
    }
170
171
    /**
172
     * Checks whether an event has any registered listeners.
173
     *
174
     * @param string $eventName
175
     *
176
     * @return bool
177
     */
178
    public function hasEventListeners($eventName)
179
    {
180
        $this->ensureEventDispatcherMiddleware();
181
182
        return $this->dispatcherMiddleware->dispatcher()->hasEventListeners($eventName);
183
    }
184
185
    /**
186
     * Checks whether has any registered listener.
187
     *
188
     * @return bool
189
     */
190
    public function hasListeners()
191
    {
192
        $this->ensureEventDispatcherMiddleware();
193
194
        return $this->dispatcherMiddleware->dispatcher()->hasListeners();
195
    }
196
}
197