Issues (17)

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.

Handler/DefaultEventHandler.php (5 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
/**
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\Console\Handler;
13
14
use Cubiche\Core\EventBus\Event\EventInterface;
15
use Cubiche\Core\EventBus\Event\EventSubscriberInterface;
16
use Cubiche\Core\EventDispatcher\PostDispatchEvent;
17
use Cubiche\Core\EventDispatcher\PreDispatchEvent;
18
use Webmozart\Console\Api\IO\IO;
19
use Webmozart\Console\UI\Component\Table;
20
use Webmozart\Console\UI\Style\TableStyle;
21
22
/**
23
 * DefaultEventHandler class.
24
 *
25
 * @author Ivannis Suárez Jerez <[email protected]>
26
 */
27
class DefaultEventHandler implements EventSubscriberInterface, EventHandlerInterface
28
{
29
    /**
30
     * @var callback
31
     */
32
    protected $preDispatchHandler;
33
34
    /**
35
     * @var callback
36
     */
37
    protected $postDispatchHandler;
38
39
    /**
40
     * @var IO
41
     */
42
    protected $io;
43
44
    /**
45
     * @param IO $io
46
     */
47
    public function setIo(IO $io)
48
    {
49
        $this->io = $io;
50
    }
51
52
    /**
53
     * @param callable $handler
54
     *
55
     * @return $this
56
     */
57 View Code Duplication
    public function addPreDispatchEventHandler($handler)
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...
58
    {
59
        if (!is_callable($handler)) {
60
            throw new \InvalidArgumentException(sprintf(
61
                'Expected a callable. Got: %s',
62
                is_object($handler) ? get_class($handler) : gettype($handler)
63
            ));
64
        }
65
66
        $this->preDispatchHandler = $handler;
67
68
        return $this;
69
    }
70
71
    /**
72
     * @param callable $handler
73
     *
74
     * @return $this
75
     */
76 View Code Duplication
    public function addPostDispatchEventHandler($handler)
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...
77
    {
78
        if (!is_callable($handler)) {
79
            throw new \InvalidArgumentException(sprintf(
80
                'Expected a callable. Got: %s',
81
                is_object($handler) ? get_class($handler) : gettype($handler)
82
            ));
83
        }
84
85
        $this->postDispatchHandler = $handler;
86
87
        return $this;
88
    }
89
90
    /**
91
     * @return $this
92
     */
93
    public function clearEventHandlers()
94
    {
95
        $this->preDispatchHandler = null;
96
        $this->postDispatchHandler = null;
97
98
        return $this;
99
    }
100
101
    /**
102
     * @param PreDispatchEvent $preDispatchEvent
103
     */
104
    public function onPreDispatchEvent(PreDispatchEvent $preDispatchEvent)
105
    {
106
        if ($this->preDispatchHandler) {
107
            call_user_func($this->preDispatchHandler, $preDispatchEvent->event(), $this->io);
108
        } else {
109
            $this->io->writeLine('<c1>------------------------------------------------------------------------</c1>');
110
            $this->io->writeLine('Dispatching <c1>'.$this->eventToString($preDispatchEvent->event()).'</c1> with:');
0 ignored issues
show
$preDispatchEvent->event() of type object<Cubiche\Core\Even...patcher\EventInterface> is not a sub-type of object<Cubiche\Core\Even...s\Event\EventInterface>. It seems like you assume a child interface of the interface Cubiche\Core\EventDispatcher\EventInterface 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...
111
            $this->io->writeLine('');
112
113
            $properties = $this->objectToPropertyArray($preDispatchEvent->event());
0 ignored issues
show
$preDispatchEvent->event() of type object<Cubiche\Core\Even...patcher\EventInterface> is not a sub-type of object<Cubiche\Core\Even...s\Event\EventInterface>. It seems like you assume a child interface of the interface Cubiche\Core\EventDispatcher\EventInterface 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...
114
115
            $table = new Table(TableStyle::asciiBorder());
116
            $table->setHeaderRow(array_keys($properties));
117
            $table->addRow(array_values($properties));
118
119
            $table->render($this->io);
120
            $this->io->writeLine('');
121
        }
122
    }
123
124
    /**
125
     * @param PostDispatchEvent $postDispatchEvent
126
     */
127
    public function onPostDispatchEvent(PostDispatchEvent $postDispatchEvent)
128
    {
129
        if ($this->postDispatchHandler) {
130
            call_user_func($this->postDispatchHandler, $postDispatchEvent->event(), $this->io);
131
        } else {
132
            $this->io->writeLine('<c1>'.$this->eventToString($postDispatchEvent->event()).'</c1> success!!');
0 ignored issues
show
$postDispatchEvent->event() of type object<Cubiche\Core\Even...patcher\EventInterface> is not a sub-type of object<Cubiche\Core\Even...s\Event\EventInterface>. It seems like you assume a child interface of the interface Cubiche\Core\EventDispatcher\EventInterface 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...
133
            $this->io->writeLine('');
134
        }
135
    }
136
137
    /**
138
     * @param EventInterface $event
139
     *
140
     * @return array
141
     */
142
    protected function objectToPropertyArray(EventInterface $event)
143
    {
144
        $properties = array();
145
        $reflection = new \ReflectionClass(get_class($event));
146
147
        /** @var \ReflectionProperty $property */
148
        foreach ($reflection->getProperties() as $property) {
149
            $property->setAccessible(true);
150
151
            if (!empty($property->getValue($event))) {
152
                $value = $property->getValue($event);
153
                if ($value instanceof \DateTime) {
154
                    $value = $value->format(\DateTime::ISO8601);
155
                }
156
157
                $properties[$property->getName()] = $value;
158
            }
159
        }
160
161
        return $properties;
162
    }
163
164
    /**
165
     * @param EventInterface $event
166
     *
167
     * @return array
168
     */
169
    protected function eventToString(EventInterface $event)
170
    {
171
        $pos = strrpos($event->eventName(), '\\');
172
        if ($pos !== false) {
173
            $className = substr($event->eventName(), strrpos($event->eventName(), '\\') + 1);
174
        } else {
175
            $className = $event->eventName();
176
        }
177
178
        return strtolower(trim(preg_replace('([A-Z])', ' $0', $className)));
179
    }
180
181
    /**
182
     * {@inheritdoc}
183
     */
184
    public static function getSubscribedEvents()
185
    {
186
        return array(
187
            PreDispatchEvent::class => 'onPreDispatchEvent',
188
            PostDispatchEvent::class => 'onPostDispatchEvent',
189
        );
190
    }
191
}
192