Issues (3099)

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.

src/Kunstmaan/MediaBundle/Entity/Folder.php (1 issue)

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 Kunstmaan\MediaBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Gedmo\Mapping\Annotation as Gedmo;
8
use Gedmo\Tree\Node as GedmoNode;
9
use Kunstmaan\AdminBundle\Entity\AbstractEntity;
10
use Symfony\Component\Validator\Constraints as Assert;
11
12
/**
13
 * Class that defines a folder from the MediaBundle in the database
14
 *
15
 * @ORM\Entity(repositoryClass="Kunstmaan\MediaBundle\Repository\FolderRepository")
16
 * @ORM\Table(name="kuma_folders", indexes={
17
 *      @ORM\Index(name="idx_folder_internal_name", columns={"internal_name"}),
18
 *      @ORM\Index(name="idx_folder_name", columns={"name"}),
19
 *      @ORM\Index(name="idx_folder_deleted", columns={"deleted"})
20
 * })
21
 * @Gedmo\Tree(type="nested")
22
 * @ORM\HasLifecycleCallbacks
23
 */
24
class Folder extends AbstractEntity implements GedmoNode
25
{
26
    const TYPE_FILES = 'files';
27
    const TYPE_IMAGE = 'image';
28
    const TYPE_MEDIA = 'media';
29
    const TYPE_SLIDESHOW = 'slideshow';
30
    const TYPE_VIDEO = 'video';
31
32
    /**
33
     * @var string
34
     *
35
     * @Gedmo\Translatable
36
     * @ORM\Column(type="string")
37
     * @Assert\NotBlank()
38
     */
39
    protected $name;
40
41
    /**
42
     * @var string
43
     *
44
     * @Gedmo\Locale
45
     * Used locale to override Translation listener`s locale
46
     * this is not a mapped field of entity metadata, just a simple property
47
     */
48
    protected $locale;
49
50
    /**
51
     * @var Folder
52
     *
53
     * @ORM\ManyToOne(targetEntity="Folder", inversedBy="children", fetch="LAZY")
54
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=true)
55
     * @Gedmo\TreeParent
56
     */
57
    protected $parent;
58
59
    /**
60
     * @var ArrayCollection
61
     *
62
     * @ORM\OneToMany(targetEntity="Folder", mappedBy="parent", fetch="LAZY")
63
     * @ORM\OrderBy({"lft" = "ASC"})
64
     */
65
    protected $children;
66
67
    /**
68
     * @var ArrayCollection
69
     *
70
     * @ORM\OneToMany(targetEntity="Media", mappedBy="folder", fetch="LAZY")
71
     * @ORM\OrderBy({"name" = "ASC"})
72
     */
73
    protected $media;
74
75
    /**
76
     * @var \DateTime
77
     *
78
     * @ORM\Column(type="datetime", name="created_at")
79
     */
80
    protected $createdAt;
81
82
    /**
83
     * @var \DateTime
84
     *
85
     * @ORM\Column(type="datetime", name="updated_at")
86
     */
87
    protected $updatedAt;
88
89
    /**
90
     * @var string
91
     *
92
     * @ORM\Column(type="string", nullable=true)
93
     */
94
    protected $rel;
95
96
    /**
97
     * @var string
98
     *
99
     * @ORM\Column(type="string", name="internal_name", nullable=true)
100
     */
101
    protected $internalName;
102
103
    /**
104
     * @var int
105
     *
106
     * @ORM\Column(name="lft", type="integer", nullable=true)
107
     * @Gedmo\TreeLeft
108
     */
109
    protected $lft;
110
111
    /**
112
     * @var int
113
     *
114
     * @ORM\Column(name="lvl", type="integer", nullable=true)
115
     * @Gedmo\TreeLevel
116
     */
117
    protected $lvl;
118
119
    /**
120
     * @var int
121
     *
122
     * @ORM\Column(name="rgt", type="integer", nullable=true)
123
     * @Gedmo\TreeRight
124
     */
125
    protected $rgt;
126
127
    /**
128
     * @var bool
129
     *
130
     * @ORM\Column(type="boolean")
131
     */
132
    protected $deleted;
133
134
    /**
135
     * constructor
136
     */
137 24 View Code Duplication
    public function __construct()
138
    {
139 24
        $this->children = new ArrayCollection();
140 24
        $this->media = new ArrayCollection();
141 24
        $this->setCreatedAt(new \DateTime());
142 24
        $this->setUpdatedAt(new \DateTime());
143 24
        $this->deleted = false;
144 24
    }
145
146
    /**
147
     * @return array
148
     */
149
    public static function allTypes()
150
    {
151
        return [
152
            self::TYPE_MEDIA => self::TYPE_MEDIA,
153
            self::TYPE_IMAGE => self::TYPE_IMAGE,
154
            self::TYPE_FILES => self::TYPE_FILES,
155
            self::TYPE_SLIDESHOW => self::TYPE_SLIDESHOW,
156
            self::TYPE_VIDEO => self::TYPE_VIDEO,
157
        ];
158
    }
159
160
    /**
161
     * @return string
162
     */
163 1
    public function getTranslatableLocale()
164
    {
165 1
        return $this->locale;
166
    }
167
168
    /**
169
     * @param string $locale
170
     *
171
     * @return Folder
172
     */
173 1
    public function setTranslatableLocale($locale)
174
    {
175 1
        $this->locale = $locale;
176
177 1
        return $this;
178
    }
179
180
    /**
181
     * @return string
182
     */
183 1
    public function getRel()
184
    {
185 1
        return $this->rel;
186
    }
187
188
    /**
189
     * @param string $rel
190
     *
191
     * @return Folder
192
     */
193 1
    public function setRel($rel)
194
    {
195 1
        $this->rel = $rel;
196
197 1
        return $this;
198
    }
199
200
    /**
201
     * Get createdAd
202
     *
203
     * @return \DateTime
204
     */
205 1
    public function getCreatedAt()
206
    {
207 1
        return $this->createdAt;
208
    }
209
210
    /**
211
     * Set createdAd
212
     *
213
     * @param \DateTime $createdAt
214
     *
215
     * @return Folder
216
     */
217 24
    public function setCreatedAt($createdAt)
218
    {
219 24
        $this->createdAt = $createdAt;
220
221 24
        return $this;
222
    }
223
224
    /**
225
     * Get updatedAt
226
     *
227
     * @return \DateTime
228
     */
229 1
    public function getUpdatedAt()
230
    {
231 1
        return $this->updatedAt;
232
    }
233
234
    /**
235
     * Set updatedAt
236
     *
237
     * @param \DateTime $updatedAt
238
     *
239
     * @return Folder
240
     */
241 24
    public function setUpdatedAt($updatedAt)
242
    {
243 24
        $this->updatedAt = $updatedAt;
244
245 24
        return $this;
246
    }
247
248
    /**
249
     * @return Folder[]:
250
     */
251 1 View Code Duplication
    public function getParents()
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...
252
    {
253 1
        $parent = $this->getParent();
254 1
        $parents = array();
255 1
        while ($parent !== null) {
256 1
            $parents[] = $parent;
257 1
            $parent = $parent->getParent();
258
        }
259
260 1
        return array_reverse($parents);
261
    }
262
263
    /**
264
     * Get parent
265
     *
266
     * @return Folder
267
     */
268 3
    public function getParent()
269
    {
270 3
        return $this->parent;
271
    }
272
273
    /**
274
     * Set parent
275
     *
276
     * @param Folder $parent
277
     *
278
     * @return Folder
279
     */
280 4
    public function setParent(Folder $parent = null)
281
    {
282 4
        $this->parent = $parent;
283
284 4
        return $this;
285
    }
286
287
    /**
288
     * Add a child
289
     *
290
     * @param Folder $child
291
     *
292
     * @return Folder
293
     */
294 2
    public function addChild(Folder $child)
295
    {
296 2
        $this->children[] = $child;
297 2
        $child->setParent($this);
298
299 2
        return $this;
300
    }
301
302
    /**
303
     * Add file
304
     *
305
     * @param Media $media
306
     *
307
     * @return Folder
308
     */
309 2
    public function addMedia(Media $media)
310
    {
311 2
        $this->media[] = $media;
312
313 2
        return $this;
314
    }
315
316
    /**
317
     * Get media
318
     *
319
     * @param bool $includeDeleted
320
     *
321
     * @return ArrayCollection
322
     */
323 2 View Code Duplication
    public function getMedia($includeDeleted = false)
324
    {
325 2
        if ($includeDeleted) {
326 1
            return $this->media;
327
        }
328
329 2
        return $this->media->filter(
330
            function (Media $entry) {
331 2
                if ($entry->isDeleted()) {
332 1
                    return false;
333
                }
334
335 2
                return true;
336 2
            }
337
        );
338
    }
339
340
    /**
341
     * @param int $id
342
     *
343
     * @return bool
344
     */
345 1
    public function hasActive($id)
346
    {
347 1
        foreach ($this->getChildren() as $child) {
348 1
            if ($child->hasActive($id) || $child->getId() == $id) {
349 1
                return true;
350
            }
351
        }
352
353 1
        return false;
354
    }
355
356
    /**
357
     * Get child folders
358
     *
359
     * @param bool $includeDeleted
360
     *
361
     * @return ArrayCollection
362
     */
363 3 View Code Duplication
    public function getChildren($includeDeleted = false)
364
    {
365 3
        if ($includeDeleted) {
366 1
            return $this->children;
367
        }
368
369 3
        return $this->children->filter(
370
            function (Folder $entry) {
371 3
                if ($entry->isDeleted()) {
372 1
                    return false;
373
                }
374
375 3
                return true;
376 3
            }
377
        );
378
    }
379
380
    /**
381
     * @param ArrayCollection $children
382
     *
383
     * @return Folder
384
     */
385 1
    public function setChildren($children)
386
    {
387 1
        $this->children = $children;
388
389 1
        return $this;
390
    }
391
392
    /**
393
     * @return bool
394
     */
395 4
    public function isDeleted()
396
    {
397 4
        return $this->deleted;
398
    }
399
400
    /**
401
     * @param bool $deleted
402
     *
403
     * @return Folder
404
     */
405 2
    public function setDeleted($deleted)
406
    {
407 2
        $this->deleted = $deleted;
408
409 2
        return $this;
410
    }
411
412
    /**
413
     * @return string
414
     */
415 1
    public function getInternalName()
416
    {
417 1
        return $this->internalName;
418
    }
419
420
    /**
421
     * @param string $internalName
422
     *
423
     * @return Folder
424
     */
425 1
    public function setInternalName($internalName)
426
    {
427 1
        $this->internalName = $internalName;
428
429 1
        return $this;
430
    }
431
432
    /**
433
     * @return string
434
     */
435 1
    public function __toString()
436
    {
437 1
        return $this->getName();
438
    }
439
440
    /**
441
     * @return string
442
     */
443 2
    public function getName()
444
    {
445 2
        return $this->name;
446
    }
447
448
    /**
449
     * @param string $name
450
     *
451
     * @return Folder
452
     */
453 2
    public function setName($name)
454
    {
455 2
        $this->name = $name;
456
457 2
        return $this;
458
    }
459
460
    /**
461
     * @param int $lft
462
     *
463
     * @return Folder
464
     */
465 1
    public function setLeft($lft)
466
    {
467 1
        $this->lft = $lft;
468
469 1
        return $this;
470
    }
471
472
    /**
473
     * @return int
474
     */
475 1
    public function getLeft()
476
    {
477 1
        return $this->lft;
478
    }
479
480
    /**
481
     * @param int $lvl
482
     *
483
     * @return Folder
484
     */
485 2
    public function setLevel($lvl)
486
    {
487 2
        $this->lvl = $lvl;
488
489 2
        return $this;
490
    }
491
492
    /**
493
     * @param int $rgt
494
     *
495
     * @return Folder
496
     */
497 1
    public function setRight($rgt)
498
    {
499 1
        $this->rgt = $rgt;
500
501 1
        return $this;
502
    }
503
504
    /**
505
     * @return int
506
     */
507 1
    public function getRight()
508
    {
509 1
        return $this->rgt;
510
    }
511
512
    /**
513
     * @return string
514
     */
515 1
    public function getOptionLabel()
516
    {
517 1
        return str_repeat(
518 1
            '-',
519 1
            $this->getLevel()
520 1
        ) . ' ' . $this->getName();
521
    }
522
523
    /**
524
     * @return int
525
     */
526 2
    public function getLevel()
527
    {
528 2
        return $this->lvl;
529
    }
530
531
    /**
532
     * @ORM\PreUpdate
533
     */
534 1
    public function preUpdate()
535
    {
536 1
        $this->setUpdatedAt(new \DateTime());
537 1
    }
538
}
539