Issues (6)

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/events/EventsTree.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 Ariadne Component Library.
5
 *
6
 * (c) Muze <[email protected]>
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 arc\events;
13
14
/**
15
 *	This class implements an event stack on which listeners can be added and removed and events can be fired.
16
 */
17
class EventsTree implements EventsTreeInterface
18
{
19
    use \arc\traits\Proxy {
20
        \arc\traits\Proxy::__construct as private ProxyConstruct;
21
    }
22
23
    private $tree = null;
24
25
    /**
26
     *	@param \arc\tree\NamedNode $tree The tree storage for event listeners.
27
     */
28 10
    public function __construct($tree)
29
    {
30 10
        $this->ProxyConstruct( $tree );
31 10
        $this->tree = $tree;
32 10
    }
33
34
    /**
35
     *	Adds an event listener for the given event and returns it.
36
     *	@param string $eventName The event to listen for
37
     *   @param callable $callback The function to call when the event occurs.
38
     *   @return Listener
39
     */
40 12
    public function listen($eventName, $callback)
41
    {
42 12
        return $this->addListener( $eventName, $callback, false );
43
    }
44
45
    /**
46
     *	Adds an event listener for the given event and returns it. The listener
47
     *	will trigger in the capture phase - before any listeners in the listen phase.
48
     *	@param string $eventName The name of the event to listen for.
49
     *   @param callable $callback The function to call when the event occurs.
50
     *	@return Listener
51
     */
52 4
    public function capture($eventName, $callback)
53
    {
54 4
        return $this->addListener( $eventName, $callback, true );
55
    }
56
57
    /**
58
     *	Fires an event. If the event objects preventDefault() method has been called it
59
     *	will return false, otherwise the - potentially changed - eventData will be returned.
60
     *	@param string $eventName The name of the event to fire.
61
     *	@param array $eventData Optional. Data passed to each handler through the event object.
62
     *	@return false or $eventData - which may have been modified
63
     */
64 12
    public function fire( $eventName, $eventData = array() )
65
    {
66
        // FIXME: because this now uses the tree, we can't quickly check if any event listeners have been added for this eventName
67
        // so there should probably be a common list of all handled eventNames in the entire tree as a performance improvement
68 12
        $eventData['arc.path'] = $this->tree->getPath();
69 12
        $event = new Event( $eventName, $eventData );
70 12
        $this->walkListeners( $event );
71 12
        if ($event->preventDefault) {
0 ignored issues
show
The property $preventDefault is declared private in arc\events\Event. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
72 2
            $result = false;
73 1
        } else {
74 10
            $result = $event->data;
75
        }
76
77 12
        return $result;
78
    }
79
80
    /**
81
     *	Returns a new EventStack with the given path.
82
     *	@param string $path The path to listen or fire an event.
83
     *	@return EventStack a new EventStack for the given path.
84
     */
85 8
    public function cd($path)
86
    {
87 8
        return new EventsTree( $this->tree->cd( $path ) );
88
    }
89
90
    /**
91
     *	Non-fluent api method to add a listener.
92
     *	@param string $eventName The name of the event to listen for.
93
     *	@param Callable $callback The callback method to call.
94
     *	@param bool $capture Optional. If true listen in the capture phase. Default is false - listen phase.
95
     *	@return Listener
96
     */
97 12
    private function addListener($eventName, $callback, $capture = false)
98
    {
99 12
        $listenerSection = ( $capture ? 'capture' : 'listen' ) . '.' . $eventName;
100 12
        if (!is_callable($callback)) {
101
            throw new \arc\IllegalRequest('Method is not callable.', \arc\exceptions::ILLEGAL_ARGUMENT);
102
        }
103 12
        if (!isset( $this->tree->nodeValue[ $listenerSection ])) {
104 8
            $this->tree->nodeValue[ $listenerSection ] = array();
105 4
        }
106 12
        $this->tree->nodeValue[ $listenerSection ][] = array(
107 6
            'method' => $callback
108 6
        );
109 12
        $id = max( array_keys( $this->tree->nodeValue[ $listenerSection ] ) );
110
111 12
        return new Listener( $eventName, $id, $capture, $this );
0 ignored issues
show
$this is of type this<arc\events\EventsTree>, but the function expects a object<arc\events\Stack>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
112
    }
113
114
    /**
115
     *	Non-fluent api method to remove a listener.
116
     *	@param string $eventName The name of the event the listener is registered for.
117
     *	@param int $id The id of the listener.
118
     *	@param string $path Optional. The path the listener is registered on. Default is '/'.
0 ignored issues
show
There is no parameter named $path. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
119
     *	@param bool $capture Optional. If true the listener is triggered in the capture phase.
120
     *		Default is false.
121
     */
122 12
    public function removeListener($eventName, $id, $capture = false)
123
    {
124 12
        $listenerSection = ( $capture ? 'capture' : 'listen' ) . '.' . $eventName;
125 12
        unset( $this->tree->nodeValue[ $listenerSection ][ $id ] );
126 12
    }
127
128
    /**
129
     *	Calls each listener with the given event untill a listener returns false.
130
     */
131 12
    private function walkListeners($event)
132
    {
133
        $callListeners = function ($listeners) use ($event) {
134 12
            foreach ((array) $listeners as $listener) {
135 12
                $result = call_user_func( $listener['method'], $event );
136 12
                if ($result === false) {
137 7
                    return false; // this will stop \arc\path::walk, so other event handlers won't be called
138
                }
139 6
            }
140 12
        };
141 12
        $result = \arc\tree::parents(
142 12
            $this->tree,
143 View Code Duplication
            function ($node, $result) use ($callListeners, $event) {
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...
144 12
                if ($result !== false && isset( $node->nodeValue['capture.'.$event->name] )) {
145 10
                    return call_user_func($callListeners, $node->nodeValue['capture.'.$event->name] );
146
                }
147 8
            }
148 6
        );
149 12
        if (!isset( $result )) {
150 12
            $result = \arc\tree::dive(
151 12
                $this->tree,
152 12 View Code Duplication
                function ($node) use ($callListeners, $event) {
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...
153 12
                    if (isset( $node->nodeValue['listen.'.$event->name] )) {
154 12
                        return call_user_func($callListeners, $node->nodeValue['listen.'.$event->name ] );
155
                    }
156 8
                }
157 6
            );
158 6
        }
159
160 12
        return !isset( $result ) ? true : false;
161
    }
162
}
163