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.

Menu/Menu.php (1 issue)

Labels
Severity

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\Menu;
4
5
use Alpixel\Bundle\MenuBundle\Entity\Item;
6
use Doctrine\ORM\EntityManager;
7
8
/**
9
 * @author Alexis BUSSIERES <[email protected]>
10
 */
11
class Menu
12
{
13
    const DELETE_STRATEGY_MOVE_CHILDREN = 'delete.strategy.move_children';
14
15
    protected $entityManager;
16
17
    /**
18
     * Menu constructor.
19
     * @param EntityManager $entityManager
20
     */
21
    public function __construct(EntityManager $entityManager)
0 ignored issues
show
You have injected the EntityManager via parameter $entityManager. This is generally not recommended as it might get closed and become unusable. Instead, it is recommended to inject the ManagerRegistry and retrieve the EntityManager via getManager() each time you need it.

The EntityManager might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:

function someFunction(ManagerRegistry $registry) {
    $em = $registry->getManager();
    $em->getConnection()->beginTransaction();
    try {
        // Do something.
        $em->getConnection()->commit();
    } catch (\Exception $ex) {
        $em->getConnection()->rollback();
        $em->close();

        throw $ex;
    }
}

If that code throws an exception and the EntityManager is closed. Any other code which depends on the same instance of the EntityManager during this request will fail.

On the other hand, if you instead inject the ManagerRegistry, the getManager() method guarantees that you will always get a usable manager instance.

Loading history...
22
    {
23
        $this->entityManager = $entityManager;
24
    }
25
26
    /**
27
     * @param array $item An array of object Item
28
     * @param string $strategy Strategy to use
29
     */
30
    public function deleteItem($item, $strategy)
31
    {
32
        $this->deleteItems([$item], $strategy);
33
    }
34
35
    /**
36
     * This method delete an array of Item by different strategy.
37
     *
38
     * Strategies available:
39
     * self::DELETE_STRATEGY_MOVE_CHILDREN Remove Item and set children to the same level of the deleted Item
40
     *
41
     * @param $items
42
     * @param string $strategy Strategy to use
43
     */
44
    public function deleteItems($items, $strategy = self::DELETE_STRATEGY_MOVE_CHILDREN)
45
    {
46
        if (!is_array($items)) {
47
            throw new \InvalidArgumentException('The "$items" parameters is not an array.');
48
        }
49
50
        if (empty($items)) {
51
            return;
52
        }
53
54
        switch ($strategy) {
55
            case self::DELETE_STRATEGY_MOVE_CHILDREN:
56
                $this->deleteItemsMoveChildren($items);
57
                break;
58
            default:
59
                throw new \InvalidArgumentException('The "$stategy" parameter must be a non empty string.');
60
        }
61
62
        $this->entityManager->flush();
63
    }
64
65
    /**
66
     * This method delete Item object and manage his children by self::DELETE_STRATEGY_MOVE_CHILDREN strategy
67
     *
68
     * @param array $items An array of object Item
69
     */
70
    private function deleteItemsMoveChildren($items)
71
    {
72
73
        foreach ($items as $item) {
74
            if (!is_object($item) || !$item instanceof Item) {
75
                throw new \InvalidArgumentException(sprintf(
76
                    'An error occurred during the operation, 
77
                    the value must be an instance object of %s'
78
                ), Item::class);
79
            }
80
81
            $this->entityManager->remove($item);
82
83
            $children = $item->getChildren();
84
            $itemParent = $item->getParent();
85
86
            if (empty($children) || empty($itemParent)) {
87
                continue;
88
            }
89
90
            $itemParentChildren = $itemParent->getChildren();
91
            foreach ($children as $child) {
92
                $child->setParent($itemParent);
93
                $itemParentChildren->add($child);
94
            }
95
96
            $this->entityManager->persist($itemParent);
97
        }
98
    }
99
100
    /**
101
     * @return array An array of available delete strategies
102
     */
103
    public static function getDeleteStrategiesAvailable()
104
    {
105
        return [
106
          self::DELETE_STRATEGY_MOVE_CHILDREN,
107
        ];
108
    }
109
}
110