Issues (5)

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.

src/ArrayUtils.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
namespace Bedd\Common;
3
4
use Bedd\Common\Traits\StaticClassTrait;
5
6
/**
7
 * ArrayUtils
8
 */
9
class ArrayUtils
10
{
11
    use StaticClassTrait;
12
13
    /**
14
     * Test whether an array contains one or more keys by defined $type
15
     *
16
     * @param string $type the Type: string|int
17
     * @param array $input
18
     * @param bool $only
19
     * @param bool $allow_empty Should an empty $input return true
20
     * @return bool
21
     */
22
    private static function hasKeysByType($type, array $input, $only = false, $allow_empty = false)
23
    {
24
        if (!is_array($input)) {
25
            return false;
26
        }
27
        if (empty($input)) {
28
            return $allow_empty;
29
        }
30
        $count = count(array_filter(array_keys($input), 'is_'.strtolower($type)));
31
        return  $only ? $count === count($input) : $count > 0;
32
    }
33
    /**
34
     * Test whether an array contains one or more string keys
35
     *
36
     * @param array $input
37
     * @param bool $only
38
     * @param bool $allow_empty Should an empty $input return true
39
     * @return bool
40
     */
41
    public static function hasStringKeys(array $input, $only = false, $allow_empty = false)
42
    {
43
        return self::hasKeysByType('string', $input, $only, $allow_empty);
44
    }
45
46
    /**
47
     * Test whether an array contains one or more integer keys
48
     *
49
     * @param array $input
50
     * @param bool $only
51
     * @param bool $allow_empty Should an empty $input return true
52
     * @return bool
53
     */
54
    public static function hasIntegerKeys(array $input, $only = false, $allow_empty = false)
55
    {
56
        return self::hasKeysByType('int', $input, $only, $allow_empty);
57
    }
58
59
    /**
60
     * Returns the value of the first found key-name
61
     *
62
     * @param array $input
63
     * @param string[] $keys
64
     * @param mixed $default
65
     * @return mixed
66
     */
67
    public static function findValueByKeys(array $input, array $keys, $default = null)
68
    {
69
        $return = $default;
70
        foreach ($keys as $key) {
71
            if (isset($input[$key])) {
72
                $return = $input[$key];
73
                break;
74
            }
75
        }
76
        return $return;
77
    }
78
79
    /**
80
     * Flatten a multi-dimensional aray into a one dimensional array
81
     *
82
     * @param array $input
83
     * @param string $preserve_keys
84
     * @return array
85
     */
86
    public static function flatten(array $input, $preserve_keys = false)
87
    {
88
        $return = [];
89
        $awr_func = $preserve_keys ?
90
            function($v, $k) use (&$return) {$return[$k] = $v; } :
0 ignored issues
show
Opening brace must be the last content on the line
Loading history...
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
91
            function($v) use (&$return) {$return[] = $v; }
0 ignored issues
show
Opening brace must be the last content on the line
Loading history...
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
92
        ;
93
        array_walk_recursive($input, $awr_func);
94
        return $return;
95
    }
96
97
    /**
98
     * Rename a key inside a dimensional array
99
     *
100
     * @param array $input
101
     * @param string old_key
102
     * @param string new_key
103
     * @return array
104
     */
105
    public static function renameKey(array $input, $old_key, $new_key)
106
    {
107
        $ret = $input;
108
        if ($old_key !== $new_key && array_key_exists($old_key, $input)) {
109
            $keys = array_keys($input);
110
            $offset = array_search($old_key, $keys);
111
            $keys[$offset] = $new_key;
112
            $ret = array_combine($keys, $input);
113
        }
114
        return $ret;
115
    }
116
}
117