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.

Kunstmaan/AdminBundle/Helper/Menu/MenuBuilder.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\AdminBundle\Helper\Menu;
4
5
use Symfony\Component\DependencyInjection\ContainerInterface;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\RequestStack;
8
9
/**
10
 * The MenuBuilder will build the top menu and the side menu of the admin interface
11
 */
12
class MenuBuilder
13
{
14
    /**
15
     * @var MenuAdaptorInterface[]
16
     */
17
    private $adaptors = array();
18
19
    /**
20
     * @var MenuAdaptorInterface[]
21
     */
22
    private $sorted = array();
23
24
    /**
25
     * @var TopMenuItem[]
26
     */
27
    private $topMenuItems = null;
28
29
    /**
30
     * @var ContainerInterface
31
     */
32
    private $container;
33
34
    /**
35
     * @var MenuItem|null
36
     */
37
    private $currentCache = null;
38
39
    /** @var RequestStack */
40
    private $requestStack;
41
42
    /**
43
     * @param ContainerInterface|RequestStack $requestStack
44
     */
45 7 View Code Duplication
    public function __construct(/* RequestStack */ $requestStack)
46
    {
47 7
        if ($requestStack instanceof ContainerInterface) {
48 1
            @trigger_error(sprintf('Passing the container as the first argument of "%s" is deprecated in KunstmaanAdminBundle 5.4 and will be removed in KunstmaanAdminBundle 6.0. Inject the "request_stack" service instead.', __CLASS__), E_USER_DEPRECATED);
49
50 1
            $this->container = $requestStack;
51 1
            $this->requestStack = $this->container->get('request_stack');
52
53 1
            return;
54
        }
55
56 6
        $this->requestStack = $requestStack;
57 6
    }
58
59
    /**
60
     * Add menu adaptor
61
     *
62
     * @param MenuAdaptorInterface $adaptor
63
     */
64 2
    public function addAdaptMenu(MenuAdaptorInterface $adaptor, $priority = 0)
65
    {
66 2
        $this->adaptors[$priority][] = $adaptor;
67 2
        unset($this->sorted);
68 2
    }
69
70
    /**
71
     * Get current menu item
72
     *
73
     * @return MenuItem|null
74
     */
75 4
    public function getCurrent()
76
    {
77 4
        if ($this->currentCache !== null) {
78 1
            return $this->currentCache;
79
        }
80
        /* @var $active MenuItem */
81 4
        $active = null;
82
        do {
83
            /* @var MenuItem[] $children */
84 4
            $children = $this->getChildren($active);
85 4
            $foundActiveChild = false;
86 4
            foreach ($children as $child) {
87 4
                if ($child->getActive()) {
88 3
                    $foundActiveChild = true;
89 3
                    $active = $child;
90
91 3
                    break;
92
                }
93
            }
94 4
        } while ($foundActiveChild);
95 4
        $this->currentCache = $active;
96
97 4
        return $active;
98
    }
99
100
    /**
101
     * Get breadcrumb path for current menu item
102
     *
103
     * @return MenuItem[]
104
     */
105 1
    public function getBreadCrumb()
106
    {
107 1
        $result = array();
108 1
        $current = $this->getCurrent();
109 1
        while (!\is_null($current)) {
110 1
            array_unshift($result, $current);
111 1
            $current = $current->getParent();
112
        }
113
114 1
        return $result;
115
    }
116
117
    /**
118
     * Get top parent menu of current menu item
119
     *
120
     * @return TopMenuItem|null
121
     */
122 3
    public function getLowestTopChild()
123
    {
124 3
        $current = $this->getCurrent();
125 3
        while (!\is_null($current)) {
126 2
            if ($current instanceof TopMenuItem) {
127 2
                return $current;
128
            }
129 1
            $current = $current->getParent();
130
        }
131
132 1
        return null;
133
    }
134
135
    /**
136
     * Get all top menu items
137
     *
138
     * @return MenuItem[]
139
     */
140 2
    public function getTopChildren()
141
    {
142 2
        if (\is_null($this->topMenuItems)) {
143
            /* @var $request Request */
144 2
            $request = $this->requestStack->getCurrentRequest();
145 2
            $this->topMenuItems = array();
146 2
            foreach ($this->getAdaptors() as $menuAdaptor) {
147 2
                $menuAdaptor->adaptChildren($this, $this->topMenuItems, null, $request);
148
            }
149
        }
150
151 2
        return $this->topMenuItems;
152
    }
153
154
    /**
155
     * Get immediate children of the specified menu item
156
     *
157
     * @param MenuItem $parent
0 ignored issues
show
Should the type for parameter $parent not be null|MenuItem?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
158
     *
159
     * @return MenuItem[]
160
     */
161 1
    public function getChildren(MenuItem $parent = null)
162
    {
163 1
        if ($parent === null) {
164 1
            return $this->getTopChildren();
165
        }
166
        /* @var $request Request */
167 1
        $request = $this->requestStack->getCurrentRequest();
168 1
        $result = array();
169 1
        foreach ($this->getAdaptors() as $menuAdaptor) {
170 1
            $menuAdaptor->adaptChildren($this, $result, $parent, $request);
171
        }
172
173 1
        return $result;
174
    }
175
176 2
    private function getAdaptors()
177
    {
178 2
        if (!isset($this->sorted)) {
179 2
            $this->sortAdaptors();
180
        }
181
182 2
        return $this->sorted;
183
    }
184
185
    /**
186
     * Sorts the internal list of adaptors by priority.
187
     */
188 2 View Code Duplication
    private function sortAdaptors()
189
    {
190 2
        $this->sorted = array();
191
192 2
        if (isset($this->adaptors)) {
193 2
            krsort($this->adaptors);
194 2
            $this->sorted = array_merge(...$this->adaptors);
195
        }
196 2
    }
197
}
198