Issues (21)

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.

Services/ArrayAccessor.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
3
namespace Pouzor\MongoDBBundle\Services;
4
5
6
class ArrayAccessor
7
{
8
9
    /**
10
     * Replace an array key with another while keeping value
11
     *
12
     * @param array $array
13
     * @param $key1
14
     * @param $key2
15
     * @return array
16
     */
17 1
    public static function replaceKey(&$array, $key1, $key2)
18
    {
19 1
        $keys = array_keys($array);
20 1
        $index = array_search($key1, $keys, true);
21
22 1
        if ($index !== false) {
23 1
            $keys[$index] = $key2;
24 1
            $array = array_combine($keys, $array);
25 1
        }
26
27 1
        return $array;
28
    }
29
30
    /**
31
     * Get a reference from an array using a path with dot notation. Ex:
32
     *
33
     * array(
34
     *      'person' => [
35
     *           'name' => 'john',
36
     *           'lastname' => 'smith',
37
     *           'childs' => [
38
     *               [ 'name' => 'victor'],
39
     *               [ 'name' => 'david']
40
     *           ]
41
     *      ]
42
     * )
43
     *
44
     * will return for:
45
     *
46
     * person.name = john
47
     * person.childs.0.name = victor
48
     *
49
     * @param array $data
50
     * @param $path
51
     * @param $default
52
     * @return array|null
53
     */
54 3
    public static function dget(array &$data, $path, $default = null)
55
    {
56 3
        $keys = explode('.', $path);
57 3
        foreach ($keys as $k) {
58 3
            if (isset($data[$k])) {
59 3
                $data =& $data[$k];
60 3
            } else {
61 1
                return $default;
62
            }
63 3
        }
64 3
        return $data;
65
    }
66
67
    /**
68
     * Set a reference from an array using a path with dot notation. Ex:
69
     *
70
     * array(
71
     *      'person' => [
72
     *           'name' => 'john',
73
     *           'lastname'='smith',
74
     *           'childs': [
75
     *               [ 'name' => 'victor'],
76
     *               [ 'name' => 'david']
77
     *           ]
78
     *      ]
79
     * )
80
     *
81
     * will set for:
82
     *
83
     * person.name = john
84
     * person.childs.0.name = victor
85
     *
86
     *
87
     * @param array $data
88
     * @param $path
89
     * @param $value
90
     */
91 1
    public static function dset(array &$data, $path, $value)
92
    {
93 1
        $keys = explode('.', $path);
94 1
        $last = array_pop($keys);
95 1
        foreach ($keys as $k) {
96 1
            if (isset($data[$k]) && is_array($data[$k])) {
97 1
                $data =& $data[$k];
98 1
            } else {
99 1
                $data[$k] = array();
100 1
                $data =& $data[$k];
101
            }
102 1
        }
103 1
        $data[$last] = $value;
104 1
    }
105
106
    /**
107
     * Count a reference from an array using a path with do notation. Ex:
108
     *
109
     * array(
110
     *      'person' => [
111
     *           'name' => 'john',
112
     *           'lastname'='smith',
113
     *           'childs': [
114
     *               [ 'name' => 'victor'],
115
     *               [ 'name' => 'david']
116
     *           ]
117
     *      ]
118
     * )
119
     *
120
     * will return for:
121
     *
122
     * person.name = 1
123
     * person.childs = 2
124
     *
125
     * @param array $data
126
     * @param $path
127
     * @return int|null
128
     */
129 1
    public static function dcount(array &$data, $path)
130
    {
131 1
        $keys = explode('.', $path);
132 1
        $last = array_pop($keys);
133 1 View Code Duplication
        foreach ($keys as $k) {
0 ignored issues
show
This code seems to be duplicated across 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...
134 1
            if (isset($data[$k]) && is_array($data[$k])) {
135 1
                $data =& $data[$k];
136 1
            } else {
137 1
                return null;
138
            }
139 1
        }
140 1
        return isset($data[$last]) && is_array($data[$last]) ? count($data[$last]) : null;
141
    }
142
143
    /**
144
     * Deletes a reference from an array using a path with do notation. Ex:
145
     *
146
     * array(
147
     *      'person' => [
148
     *           'name' => 'john',
149
     *           'lastname'='smith',
150
     *           'childs': [
151
     *               [ 'name' => 'victor'],
152
     *               [ 'name' => 'david']
153
     *           ]
154
     *      ]
155
     * )
156
     *
157
     * will delete for:
158
     *
159
     * person.name
160
     *
161
     * will result in
162
     *
163
     * array(
164
     *      'person' => [
165
     *           'lastname'='smith',
166
     *           'childs': [
167
     *               [ 'name' => 'victor'],
168
     *               [ 'name' => 'david']
169
     *           ]
170
     *      ]
171
     * )
172
     *
173
     * @param array $data
174
     * @param $path
175
     */
176 1
    public static function ddel(array &$data, $path)
177
    {
178 1
        $keys = explode('.', $path);
179 1
        $last = array_pop($keys);
180 1 View Code Duplication
        foreach ($keys as $k) {
0 ignored issues
show
This code seems to be duplicated across 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...
181 1
            if (isset($data[$k]) && is_array($data[$k])) {
182 1
                $data =& $data[$k];
183 1
            } else {
184 1
                return;
185
            }
186 1
        }
187 1
        unset($data[$last]);
188 1
    }
189
190
    /**
191
     * @param $array
192
     * @param $key
193
     * @param null $default
194
     * @return null
195
     */
196 1
    public static function get_key_exist($array, $key, $default = null) {
197
198 1
        if (isset($array[$key]))
199 1
            return $array[$key];
200
201 1
        return $default;
202
203
    }
204
}
205