Issues (4)

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.

Base/AbstractBranch.php (2 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
namespace ezTreeBuilder\Base;
3
4
/**
5
 * Branch abstract class - Limited concern to \TreeBuilder\Tree
6
 *
7
 * @package ezTreeBuilder
8
 * @author Adrian Tilita <[email protected]>
9
 * @version 1.0
10
 * @abstract
11
 */
12
abstract class AbstractBranch
13
{
14
    /**
15
     * Container for current branch children
16
     * @var array
17
     */
18
    private $children = array();
19
20
    /**
21
     * Reference to the current branch parent
22
     * @var Branch
23
     */
24
    private $parent;
25
26
    /**
27
     * The depth of the item
28
     * @var int
29
     */
30
    private $depth;
31
32
    /**
33
     * The left number of the branch
34
     * @var int
35
     */
36
    private $left;
37
38
    /**
39
     * The right number of the branch
40
     * @var int
41
     */
42
    private $right;
43
44
    /**
45
     * Establish if the item is a leaf
46
     * @var boolean
47
     */
48
    private $isLeaf;
49
50
    /**
51
     * Set the Parent of the current branch
52
     * @param Branch $item
53
     * @return Branch
54
     */
55
    public function setParent(Branch $item)
56
    {
57
        $this->parent = $item;
58
        return $this;
59
    }
60
61
    /**
62
     * Verify if the current branch has a parent
63
     * @return boolean
64
     */
65
    public function hasParent()
66
    {
67
        if (!isset($this->parent)) {
68
            return false;
69
        }
70
        return true;
71
    }
72
73
    /**
74
     * Get the current branch's parent
75
     * @return Branch
76
     * @throws \Exception
77
     */
78
    public function getParent()
79
    {
80
        if ($this->hasParent() === false) {
81
            throw new \Exception('The current branch has no parent set!');
82
        }
83
        return $this->parent;
84
    }
85
86
    /**
87
     * Get the root parent of the current branch
88
     * @return Branch
89
     */
90
    public function getRootParent()
91
    {
92
        if ($this->hasParent() === false) {
93
            return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (ezTreeBuilder\Base\AbstractBranch) is incompatible with the return type documented by ezTreeBuilder\Base\AbstractBranch::getRootParent of type ezTreeBuilder\Base\Branch.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
94
        }
95
        $parent = $this->getParent();
96
        while ($parent->hasParent() === true) {
97
            $parent = $parent->getParent();
98
        }
99
        return $parent;
100
    }
101
102
    /**
103
     * Adds a new branch child
104
     * @param Branch $item
105
     */
106
    public function addChild(Branch $item)
107
    {
108
        $this->children[] = $item;
109
    }
110
 
111
    /**
112
     * Verify if the current branch has any children
113
     * @return boolean
114
     */
115
    public function hasChildren()
116
    {
117
        if (empty($this->children)) {
118
            return false;
119
        }
120
        return true;
121
    }
122
123
    /**
124
     * Return the current branch children
125
     * @return array - array(Branch, Branch)
126
     * @throws \Exception
127
     */
128
    public function getChildren()
129
    {
130
        if ($this->hasChildren() === false) {
131
            throw new \Exception('The current branch has no childs!');
132
        }
133
        return $this->children;
134
    }
135
136
    /**
137
     * Set the branch depth
138
     * @param int $depth
139
     * @return AbstractBranch
140
     */
141
    public function setDepth($depth)
142
    {
143
        $this->depth = $depth;
144
        return $this;
145
    }
146
147
    /**
148
     * Get the branch depth
149
     * @return int
150
     */
151
    public function getDepth()
152
    {
153
        return $this->depth;
154
    }
155
156
    /**
157
     * Set Tree Left value
158
     * @param int $value
159
     * @return AbstractBranch
160
     */
161
    public function setLeft($value)
162
    {
163
        $this->left = $value;
164
        return $this;
165
    }
166
167
    /**
168
     * Get Tree Left value
169
     * @return int
170
     */
171
    public function getLeft()
172
    {
173
        return $this->left;
174
    }
175
176
177
    /**
178
     * Set Tree Right value
179
     * @param int $value
180
     * @return AbstractBranch
181
     */
182
    public function setRight($value)
183
    {
184
        $this->right = $value;
185
        return $this;
186
    }
187
188
    /**
189
     * Get Tree Right value
190
     * @return int
191
     */
192
    public function getRight()
193
    {
194
        return $this->right;
195
    }
196
197
    /**
198
     * Set the Leaf state
199
     * @param boolean $isLeaf
200
     * @return AbstractBranch
201
     */
202
    public function setIsLeaf($isLeaf)
203
    {
204
        $this->isLeaf = $isLeaf;
205
        return $this;
206
    }
207
208
    /**
209
     * Return the leaf state of the item
210
     * @return boolean
211
     */
212
    public function isLeaf()
213
    {
214
        return $this->isLeaf;
215
    }
216
217
    /**
218
     * Get the entire Item as array
219
     * @return array
220
     */
221
    public function getAsArray()
222
    {
223
        $returnedArray = array();
224
        $returnedArray['id'] = $this->getId();
225
        $returnedArray['parent_id'] = $this->hasParent() ? $this->getParentId() : 0;
0 ignored issues
show
The method getParentId() does not exist on ezTreeBuilder\Base\AbstractBranch. Did you maybe mean getParent()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
226
        $returnedArray['data'] = $this->getData();
227
        $returnedArray['depth'] = $this->getDepth();
228
        $returnedArray['left'] = $this->getLeft();
229
        $returnedArray['right'] = $this->getRight();
230
        $returnedArray['is_leaf'] = $this->isLeaf();
231
        return $returnedArray;
232
    }
233
}
234