Issues (28)

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/Support/Arr.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
 * Created by PhpStorm.
4
 * User: lenovo
5
 * Date: 6/13/2018
6
 * Time: 11:36 PM
7
 */
8
9
namespace TimSDK\Support;
10
11
use ArrayAccess;
12
13
class Arr
14
{
15
    /**
16
     * Determine whether the given value is array accessible.
17
     *
18
     * @param  mixed  $value
19
     * @return bool
20
     */
21
    public static function accessible($value)
22
    {
23
        return is_array($value) || $value instanceof ArrayAccess;
24
    }
25
26
    /**
27
     * Determine if the given key exists in the provided array.
28
     *
29
     * @param  \ArrayAccess|array  $array
30
     * @param  string|int  $key
31
     * @return bool
32
     */
33
    public static function exists($array, $key)
34
    {
35
        if ($array instanceof ArrayAccess) {
36
            return $array->offsetExists($key);
37
        }
38
39
        return array_key_exists($key, $array);
40
    }
41
42
    /**
43
     * Get a subset of the items from the given array.
44
     *
45
     * @param  array  $array
46
     * @param  array|string  $keys
47
     * @return array
48
     */
49
    public static function only($array, $keys)
50
    {
51
        if (is_string($keys)) {
52
            $keys = explode(',', str_replace(' ', '', $keys));
53
        }
54
55
        return array_intersect_key($array, array_flip((array) $keys));
56
    }
57
    
58
    /**
59
     * Set an array item to a given value using "dot" notation.
60
     *
61
     * If no key is given to the method, the entire array will be replaced.
62
     *
63
     * @param array  $array
64
     * @param string $key
65
     * @param mixed  $value
66
     *
67
     * @return array
68
     */
69
    public static function set(&$array, $key, $value)
70
    {
71
        if (is_null($key)) {
72
            return $array = $value;
73
        }
74
75
        $keys = explode('.', $key);
76
77
        while (count($keys) > 1) {
78
            $key = array_shift($keys);
79
            // If the key doesn't exist at this depth, we will just create an empty array
80
            // to hold the next value, allowing us to create the arrays to hold final
81
            // values at the correct depth. Then we'll keep digging into the array.
82
            if (!isset($array[$key]) || !is_array($array[$key])) {
83
                $array[$key] = [];
84
            }
85
            $array = &$array[$key];
86
        }
87
        $array[array_shift($keys)] = $value;
88
        return $array;
89
    }
90
91
    /**
92
     * Get an item from an array using "dot" notation.
93
     *
94
     * @param array  $array
95
     * @param string $key
96
     * @param mixed  $default
97
     *
98
     * @return mixed
99
     */
100
    public static function get($array, $key, $default = null)
101
    {
102
        if (is_null($key)) {
103
            return $array;
104
        }
105
106
        if (isset($array[$key])) {
107
            return $array[$key];
108
        }
109
110
        foreach (explode('.', $key) as $segment) {
111
            if (!is_array($array) || !array_key_exists($segment, $array)) {
112
                return \TimSDK\value($default);
113
            }
114
            $array = $array[$segment];
115
        }
116
117
        return $array;
118
    }
119
120
    /**
121
     * To determine Whether an array item exists
122
     *
123
     * @static
124
     * @param array        $array
125
     * @param array|string $keys
126
     * @return bool
127
     */
128
    public static function has($array, $keys)
129
    {
130
        if (is_null($keys)) {
131
            return false;
132
        }
133
134
        $keys = (array) $keys;
135
136
        if (! $array) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $array of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
137
            return false;
138
        }
139
140
        if ($keys === []) {
141
            return false;
142
        }
143
144
        foreach ($keys as $key) {
145
            $subKeyArray = $array;
146
147
            if (static::exists($array, $key)) {
148
                continue;
149
            }
150
151
            foreach (explode('.', $key) as $segment) {
152
                if (static::accessible($subKeyArray) && static::exists($subKeyArray, $segment)) {
153
                    $subKeyArray = $subKeyArray[$segment];
154
                } else {
155
                    return false;
156
                }
157
            }
158
        }
159
160
        return true;
161
    }
162
163
    /**
164
     * Remove one or many array items from a given array using "dot" notation.
165
     *
166
     * @param array        $array
167
     * @param array|string $keys
168
     */
169
    public static function forget(&$array, $keys)
170
    {
171
        $original = &$array;
172
        foreach ((array) $keys as $key) {
173
            $parts = explode('.', $key);
174
            while (count($parts) > 1) {
175
                $part = array_shift($parts);
176
177
                if (!static::exists($array, $part)) {
178
                    return ;
179
                }
180
181
                if (is_array($array[$part])) {
182
                    $array = &$array[$part];
183
                }
184
            }
185
            unset($array[array_shift($parts)]);
186
            // clean up after each pass
187
            $array = &$original;
188
        }
189
    }
190
}
191