Issues (30)

Security Analysis    not enabled

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.

Entity/Item.php (4 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
namespace Alpixel\Bundle\MenuBundle\Entity;
4
5
use Alpixel\Bundle\MenuBundle\Model\ItemInterface;
6
use Alpixel\Bundle\MenuBundle\Model\MenuInterface;
7
use Alpixel\Bundle\MenuBundle\Validator\Constraints\RouteExists;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\ORM\Mapping as ORM;
10
use Gedmo\Mapping\Annotation as Gedmo;
11
12
/**
13
 * @ORM\Table(name="alpixel_menu_item")
14
 * @ORM\Entity(repositoryClass="Alpixel\Bundle\MenuBundle\Entity\Repository\ItemRepository")
15
 */
16
class Item implements ItemInterface
17
{
18
    const URI_TYPE_ANCHOR = 'anchor';
19
    const URI_TYPE_EXTERNAL = 'external';
20
    const URI_TYPE_INTERNAL = 'internal';
21
22
    /**
23
     * @var int
24
     *
25
     * @ORM\Column(name="item_id", type="integer", nullable=false)
26
     * @ORM\Id
27
     * @ORM\GeneratedValue(strategy="IDENTITY")
28
     */
29
    protected $id;
30
31
    /**
32
     * @Gedmo\SortableGroup
33
     *
34
     * @ORM\ManyToOne(targetEntity="Alpixel\Bundle\MenuBundle\Entity\Item", inversedBy="children")
35
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="item_id", onDelete="SET NULL")
36
     */
37
    protected $parent;
38
39
    /**
40
     * @ORM\OneToMany(targetEntity="Alpixel\Bundle\MenuBundle\Entity\Item", mappedBy="parent")
41
     * @ORM\OrderBy({"position": "ASC"})
42
     */
43
    protected $children;
44
45
    /**
46
     * @Gedmo\SortableGroup
47
     *
48
     * @ORM\ManyToOne(targetEntity="Alpixel\Bundle\MenuBundle\Entity\Menu", inversedBy="items")
49
     * @ORM\JoinColumn(name="menu_id", referencedColumnName="menu_id")
50
     */
51
    protected $menu;
52
53
    /**
54
     * @var string
55
     *
56
     * @ORM\Column(name="name", type="string", length=255, nullable=false)
57
     */
58
    protected $name;
59
60
    /**
61
     * @RouteExists
62
     * @ORM\Column(name="uri", type="text", nullable=false)
63
     */
64
    protected $uri;
65
66
    /**
67
     * @Gedmo\SortablePosition
68
     *
69
     * @ORM\Column(name="position", type="integer", nullable=false)
70
     */
71
    protected $position;
72
73
    /**
74
     * @Gedmo\Slug(fields={"name"}, updatable=true, separator="_")
75
     * @ORM\Column(length=128)
76
     **/
77
    protected $slug;
78
79
    public function __construct()
80
    {
81
        $this->children = new ArrayCollection();
82
    }
83
84
    /**
85
     * Get string defined.
86
     *
87
     * @return string
88
     */
89
    public function __toString()
90
    {
91
        return (string) $this->name;
92
    }
93
94
    /**
95
     * Get Id.
96
     *
97
     * @return int
98
     */
99
    public function getId()
100
    {
101
        return $this->id;
102
    }
103
104
    /**
105
     * Get menu.
106
     *
107
     * @return Menu
108
     */
109
    public function getMenu()
110
    {
111
        return $this->menu;
112
    }
113
114
    /**
115
     * Set menu.
116
     *
117
     * @param Menu $menu
118
     *
119
     * @return self
120
     */
121
    public function setMenu(MenuInterface $menu)
122
    {
123
        $this->menu = $menu;
124
125
        return $this;
126
    }
127
128
    /**
129
     * Get parent Item.
130
     *
131
     * @return null\Item
132
     */
133
    public function getParent()
134
    {
135
        return $this->parent;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->parent; of type null|Alpixel\Bundle\MenuBundle\Model\ItemInterface adds the type Alpixel\Bundle\MenuBundle\Model\ItemInterface to the return on line 135 which is incompatible with the return type declared by the interface Alpixel\Bundle\MenuBundl...temInterface::getParent of type null|Alpixel\Bundle\MenuBundle\Model\MenuInterface.
Loading history...
136
    }
137
138
    /**
139
     * Set parent Item.
140
     *
141
     * @param ItemInterface $menu
0 ignored issues
show
There is no parameter named $menu. 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...
142
     *
143
     * @return self
144
     */
145
    public function setParent(ItemInterface $item = null)
146
    {
147
        $this->parent = $item;
148
149
        return $this;
150
    }
151
152
    /**
153
     * Get children of Item.
154
     *
155
     * @return ArrayCollection (Item)
156
     */
157
    public function getChildren()
158
    {
159
        $children = $this->children;
160
161
        return $children;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $children; (Doctrine\Common\Collections\ArrayCollection) is incompatible with the return type declared by the interface Alpixel\Bundle\MenuBundl...mInterface::getChildren of type Alpixel\Bundle\MenuBundl...el\null\ArrayCollection.

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...
162
    }
163
164
    /**
165
     * Set Item from ArrayCollection.
166
     *
167
     * @param null\ArrayCollection
168
     *
169
     * @return self
170
     */
171
    public function addChildren(ArrayCollection $collection)
172
    {
173
        foreach ($collection as $item) {
174
            $this->setChildren($item);
175
        }
176
177
        return $this;
178
    }
179
180
    /**
181
     * Set children of Item.
182
     *
183
     * @param Item $item
184
     *
185
     * @return self
186
     */
187
    public function setChildren(ItemInterface $item)
188
    {
189
        if ($this->children->contains($item) === false) {
190
            $this->children->add($item);
191
        }
192
193
        return $this;
194
    }
195
196
    /**
197
     * Remove children.
198
     *
199
     * @param ItemInterface $item
200
     *
201
     * @return $this
202
     */
203
    public function removeChildren(ItemInterface $item)
204
    {
205
        if ($this->children->contains($item) === true) {
206
            $this->children->removeElement($item);
207
        }
208
209
        return $this;
210
    }
211
212
    /**
213
     * Get name displayed in Item.
214
     *
215
     * @return string
216
     */
217
    public function getName()
218
    {
219
        return $this->name;
220
    }
221
222
    /**
223
     * Set name displayed in Item.
224
     *
225
     * @param string
226
     *
227
     * @return self
228
     */
229
    public function setName($name)
230
    {
231
        $this->name = $name;
232
233
        return $this;
234
    }
235
236
    /**
237
     * Get URL.
238
     *
239
     * @return string
240
     */
241
    public function getUri()
242
    {
243
        return $this->uri;
244
    }
245
246
    /**
247
     * Set URL.
248
     *
249
     * @param string $url
0 ignored issues
show
There is no parameter named $url. 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...
250
     *
251
     * @return self
252
     */
253
    public function setUri($uri)
254
    {
255
        $this->uri = $uri;
256
257
        return $this;
258
    }
259
260
    /**
261
     * Get position of Item.
262
     *
263
     * @return int
264
     */
265
    public function getPosition()
266
    {
267
        return $this->position;
268
    }
269
270
    /**
271
     * Set position.
272
     *
273
     * @param int $position
274
     *
275
     * @return self
276
     */
277
    public function setPosition($position)
278
    {
279
        $this->position = $position;
280
281
        return $this;
282
    }
283
284
    /**
285
     * Gets the value of slug.
286
     *
287
     * @return mixed
288
     */
289
    public function getSlug()
290
    {
291
        return $this->slug;
292
    }
293
294
    /**
295
     * Sets the value of slug.
296
     *
297
     * @param mixed $slug the slug
298
     *
299
     * @return self
300
     */
301
    public function setSlug($slug)
302
    {
303
        $this->slug = $slug;
304
305
        return $this;
306
    }
307
308
    public static function getUriType()
309
    {
310
        return [
311
            self::URI_TYPE_ANCHOR,
312
            self::URI_TYPE_EXTERNAL,
313
            self::URI_TYPE_INTERNAL,
314
        ];
315
    }
316
317
    public static function uriTypeExists($type)
318
    {
319
        return in_array($type, self::getUriType());
320
    }
321
}
322