Issues (58)

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/Arr.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 Omnipay\Spreedly;
4
5
class Arr {
6
7
    /**
8
     * Add an element to an array using "dot" notation if it doesn't exist.
9
     *
10
     * @param  array   $array
11
     * @param  string  $key
12
     * @param  mixed   $value
13
     * @return array
14
     */
15 2
    public static function add($array, $key, $value)
16
    {
17 2
        if (is_null(static::get($array, $key)))
18 2
        {
19 2
            static::set($array, $key, $value);
20 2
        }
21
22 2
        return $array;
23
    }
24
25
    /**
26
     * Divide an array into two arrays. One with keys and the other with values.
27
     *
28
     * @param  array  $array
29
     * @return array
30
     */
31 2
    public static function divide($array)
32
    {
33 2
        return array(array_keys($array), array_values($array));
34
    }
35
36
    /**
37
     * Flatten a multi-dimensional associative array with dots.
38
     *
39
     * @param  array   $array
40
     * @param  string  $prepend
41
     * @return array
42
     */
43 2
    public static function dot($array, $prepend = '')
44
    {
45 2
        $results = array();
46
47 2
        foreach ($array as $key => $value)
48
        {
49 2
            if (is_array($value))
50 2
            {
51 2
                $results = array_merge($results, static::dot($value, $prepend.$key.'.'));
52 2
            }
53
            else
54
            {
55 2
                $results[$prepend.$key] = $value;
56
            }
57 2
        }
58
59 2
        return $results;
60
    }
61
62
    /**
63
     * Get all of the given array except for a specified array of items.
64
     *
65
     * @param  array  $array
66
     * @param  array|string  $keys
67
     * @return array
68
     */
69 2
    public static function except($array, $keys)
70
    {
71 2
        static::forget($array, $keys);
72
73 2
        return $array;
74
    }
75
76
    /**
77
     * Return the first element in an array passing a given truth test.
78
     *
79
     * @param  array  $array
80
     * @param  callable  $callback
81
     * @param  mixed  $default
82
     * @return mixed
83
     */
84 4
    public static function first($array, callable $callback, $default = null)
85
    {
86 4
        foreach ($array as $key => $value)
87
        {
88 4
            if (call_user_func($callback, $key, $value)) return $value;
89 2
        }
90
91 2
        return $default;
92
    }
93
94
    /**
95
     * Return the last element in an array passing a given truth test.
96
     *
97
     * @param  array  $array
98
     * @param  callable  $callback
99
     * @param  mixed  $default
100
     * @return mixed
101
     */
102 2
    public static function last($array, callable $callback, $default = null)
103
    {
104 2
        return static::first(array_reverse($array), $callback, $default);
105
    }
106
107
    /**
108
     * Flatten a multi-dimensional array into a single level.
109
     *
110
     * @param  array  $array
111
     * @return array
112
     */
113 2
    public static function flatten($array)
114
    {
115 2
        $return = array();
116
117
        array_walk_recursive($array, function($x) use (&$return) { $return[] = $x; });
118
119 2
        return $return;
120
    }
121
122
    /**
123
     * Remove one or many array items from a given array using "dot" notation.
124
     *
125
     * @param  array  $array
126
     * @param  array|string  $keys
127
     * @return void
128
     */
129 6
    public static function forget(&$array, $keys)
130
    {
131 6
        $original = &$array;
132
133 6
        $keys = (array) $keys;
134
135 6
        if (count($keys) === 0) {
136 2
            return;
137
        }
138
139 6
        foreach ($keys as $key) {
140 6
            $parts = explode('.', $key);
141
142 6 View Code Duplication
            while (count($parts) > 1) {
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...
143 2
                $part = array_shift($parts);
144
145 2
                if (isset($array[$part]) && is_array($array[$part])) {
146 2
                    $array = &$array[$part];
147 2
                } else {
148 2
                    $parts = array();
149
                }
150 2
            }
151
152 6
            unset($array[array_shift($parts)]);
153
154
            // clean up after each pass
155 6
            $array = &$original;
156 6
        }
157 6
    }
158
159
    /**
160
     * Get an item from an array using "dot" notation.
161
     *
162
     * @param  array   $array
163
     * @param  string  $key
164
     * @param  mixed   $default
165
     * @return mixed
166
     */
167 56
    public static function get($array, $key, $default = null)
168
    {
169 56
        if (is_null($key)) return $array;
170
171 52
        if (isset($array[$key])) return $array[$key];
172
173 32 View Code Duplication
        foreach (explode('.', $key) as $segment)
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...
174
        {
175 32
            if ( ! is_array($array) || ! array_key_exists($segment, $array))
176 32
            {
177 28
                return $default;
178
            }
179
180 20
            $array = $array[$segment];
181 20
        }
182
183 20
        return $array;
184
    }
185
186
    /**
187
     * Check if an item exists in an array using "dot" notation.
188
     *
189
     * @param  array   $array
190
     * @param  string  $key
191
     * @return bool
192
     */
193 2
    public static function has($array, $key)
194
    {
195 2
        if (empty($array) || is_null($key)) return false;
196
197 2
        if (array_key_exists($key, $array)) return true;
198
199 2 View Code Duplication
        foreach (explode('.', $key) as $segment)
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...
200
        {
201 2
            if ( ! is_array($array) || ! array_key_exists($segment, $array))
202 2
            {
203 2
                return false;
204
            }
205
206 2
            $array = $array[$segment];
207 2
        }
208
209 2
        return true;
210
    }
211
212
    /**
213
     * Get a subset of the items from the given array.
214
     *
215
     * @param  array  $array
216
     * @param  array|string  $keys
217
     * @return array
218
     */
219 2
    public static function only($array, $keys)
220
    {
221 2
        return array_intersect_key($array, array_flip((array) $keys));
222
    }
223
224
    /**
225
     * Get a value from the array, and remove it.
226
     *
227
     * @param  array   $array
228
     * @param  string  $key
229
     * @param  mixed   $default
230
     * @return mixed
231
     */
232 2
    public static function pull(&$array, $key, $default = null)
233
    {
234 2
        $value = static::get($array, $key, $default);
235
236 2
        static::forget($array, $key);
237
238 2
        return $value;
239
    }
240
241
    /**
242
     * Set an array item to a given value using "dot" notation.
243
     *
244
     * If no key is given to the method, the entire array will be replaced.
245
     *
246
     * @param  array   $array
247
     * @param  string  $key
248
     * @param  mixed   $value
249
     * @return array
250
     */
251 6
    public static function set(&$array, $key, $value)
252
    {
253 6
        if (is_null($key)) return $array = $value;
254
255 6
        $keys = explode('.', $key);
256
257 6 View Code Duplication
        while (count($keys) > 1)
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...
258
        {
259 4
            $key = array_shift($keys);
260
261
            // If the key doesn't exist at this depth, we will just create an empty array
262
            // to hold the next value, allowing us to create the arrays to hold final
263
            // values at the correct depth. Then we'll keep digging into the array.
264 4
            if ( ! isset($array[$key]) || ! is_array($array[$key]))
265 4
            {
266 4
                $array[$key] = array();
267 4
            }
268
269 4
            $array =& $array[$key];
270 4
        }
271
272 6
        $array[array_shift($keys)] = $value;
273
274 6
        return $array;
275
    }
276
277
    /**
278
     * Filter the array using the given callback.
279
     *
280
     * @param  array  $array
281
     * @param  callable  $callback
282
     * @return array
283
     */
284 2
    public static function where($array, callable $callback)
285
    {
286 2
        $filtered = array();
287
288 2
        foreach ($array as $key => $value)
289
        {
290 2
            if (call_user_func($callback, $key, $value)) $filtered[$key] = $value;
291 2
        }
292
293 2
        return $filtered;
294
    }
295
296
}