Issues (1)

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/Emitter.php (1 issue)

Labels
Severity

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
 * Event Emitter (HEAVILY based on evenement/evenement)
4
 *
5
 * PHP version 5
6
 *
7
 * Copyright (C) 2016 Jake Johns
8
 *
9
 * This software may be modified and distributed under the terms
10
 * of the MIT license.  See the LICENSE file for details.
11
 *
12
 * @category  Emitter
13
 * @package   Jnjxp\Event
14
 * @author    Jake Johns <[email protected]>
15
 * @copyright 2016 Jake Johns
16
 * @license   http://jnj.mit-license.org/2016 MIT License
17
 * @link      https://github.com/jnjxp/jnjxp.event
18
 */
19
20
namespace Jnjxp\Event;
21
22
/**
23
 * Emitter
24
 *
25
 * @category Emitter
26
 * @package  Jnjxp\Event
27
 * @author   Jake Johns <[email protected]>
28
 * @license  http://jnj.mit-license.org/ MIT License
29
 * @link     https://github.com/jnjxp/jnjxp.event
30
 */
31
class Emitter
32
{
33
    /**
34
     * Listener specs
35
     *
36
     * @var array
37
     *
38
     * @access protected
39
     */
40
    protected $listeners = [];
41
42
    /**
43
     * Resolver
44
     *
45
     * @var callable
46
     *
47
     * @access protected
48
     */
49
    protected $resolver;
50
51
    /**
52
     * __construct
53
     *
54
     * @param callable $resolver spec resolver
55
     *
56
     * @access public
57
     */
58 16
    public function __construct(callable $resolver = null)
59
    {
60 16
        $this->resolver = $resolver;
61 16
    }
62
63
    /**
64
     * Add Listener to event
65
     *
66
     * @param string $event    name of event
67
     * @param mixed  $listener listener spec
68
     *
69
     * @return null
70
     *
71
     * @access public
72
     *
73
     * @SuppressWarnings(PHPMD.ShortMethodName)
74
     */
75 15
    public function on($event, $listener)
76
    {
77 15
        if (!isset($this->listeners[$event])) {
78 15
            $this->listeners[$event] = [];
79
        }
80 15
        $this->listeners[$event][] = $listener;
81 15
    }
82
83
    /**
84
     * Add one time listener
85
     *
86
     * @param string $event    name of event
87
     * @param mixed  $listener listener spec
88
     *
89
     * @return null
90
     *
91
     * @access public
92
     */
93
    public function once($event, $listener)
94
    {
95 2
        $onceListener = function () use (&$onceListener, $event, $listener) {
96 2
            $this->removeListener($event, $onceListener);
97 2
            $listener = $this->resolve($listener);
0 ignored issues
show
Consider using a different name than the imported variable $listener, or did you forget to import by reference?

It seems like you are assigning to a variable which was imported through a use statement which was not imported by reference.

For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.

Change not visible in outer-scope

$x = 1;
$callable = function() use ($x) {
    $x = 2; // Not visible in outer scope. If you would like this, how
            // about using a different variable name than $x?
};

$callable();
var_dump($x); // integer(1)

Change visible in outer-scope

$x = 1;
$callable = function() use (&$x) {
    $x = 2;
};

$callable();
var_dump($x); // integer(2)
Loading history...
98 2
            call_user_func_array($listener, func_get_args());
99 2
        };
100 2
        $this->on($event, $onceListener);
101 2
    }
102
103
    /**
104
     * Remove listener
105
     *
106
     * @param string $event    name of event
107
     * @param mixed  $listener listener spec
108
     *
109
     * @return null
110
     *
111
     * @access public
112
     */
113 4
    public function removeListener($event, $listener)
114
    {
115 4
        if (isset($this->listeners[$event])) {
116 3
            $index = array_search($listener, $this->listeners[$event], true);
117 3
            if (false !== $index) {
118 3
                unset($this->listeners[$event][$index]);
119
            }
120
        }
121 4
    }
122
123
    /**
124
     * Remove all listeners
125
     *
126
     * @param null|string $event name of event
127
     *
128
     * @return null
129
     *
130
     * @access public
131
     */
132 3
    public function removeAllListeners($event = null)
133
    {
134 3
        if ($event !== null) {
135 2
            unset($this->listeners[$event]);
136
        } else {
137 1
            $this->listeners = [];
138
        }
139 3
    }
140
141
    /**
142
     * Get listeners for event
143
     *
144
     * @param string $event event anme
145
     *
146
     * @return array
147
     *
148
     * @access public
149
     */
150 13
    public function listeners($event)
151
    {
152 13
        return isset($this->listeners[$event]) ? $this->listeners[$event] : [];
153
    }
154
155
    /**
156
     * Emit event signal
157
     *
158
     * @param string $event     name of event
159
     * @param array  $arguments event arguments
160
     *
161
     * @return null
162
     *
163
     * @access public
164
     */
165 13
    public function emit($event, array $arguments = [])
166
    {
167 13
        foreach ($this->listeners($event) as $listener) {
168 9
            $listener = $this->resolve($listener);
169 9
            call_user_func_array($listener, $arguments);
170
        }
171 13
    }
172
173
    /**
174
     * Resolve
175
     *
176
     * @param mixed $spec listener spec
177
     *
178
     * @return mixed
179
     *
180
     * @access protected
181
     */
182 9
    protected function resolve($spec)
183
    {
184 9
        if (! $this->resolver) {
185 8
            return $spec;
186
        }
187
188 1
        return call_user_func($this->resolver, $spec);
189
    }
190
}
191