Issues (7)

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/Vale.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 Cocur\Vale;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Vale.
9
 *
10
 * @author    Florian Eckerstorfer <[email protected]>
11
 * @copyright 2015 Florian Eckerstorfer
12
 * @license   http://opensource.org/licenses/MIT The MIT License
13
 */
14
class Vale
15
{
16
    /**
17
     * @var Vale
18
     */
19
    private static $instance;
20
21
    /**
22
     * @return Vale
23
     */
24 1
    public static function instance()
25
    {
26 1
        if (null === self::$instance) {
27 1
            self::$instance = new self();
28 1
        }
29
30 1
        return self::$instance;
31
    }
32
33
    /**
34
     * @param mixed            $data
35
     * @param array|string|int $keys
36
     * @param mixed            $default
37
     *
38
     * @return mixed
39
     */
40 1
    public static function get($data, $keys, $default = null)
41
    {
42 1
        return self::instance()->getValue($data, $keys, $default);
43
    }
44
45
    /**
46
     * @param mixed            $data
47
     * @param array|string|int $keys
48
     * @param mixed            $value
49
     *
50
     * @return mixed
51
     */
52 1
    public static function set($data, $keys, $value)
53
    {
54 1
        return self::instance()->setValue($data, $keys, $value);
55
    }
56
57
    /**
58
     * @param mixed            $data
59
     * @param array|string|int $keys
60
     *
61
     * @return bool
62
     */
63 1
    public static function has($data, $keys)
64
    {
65 1
        return self::instance()->hasValue($data, $keys);
66
    }
67
68
    /**
69
     * @param mixed            $data
70
     * @param array|string|int $keys
71
     *
72
     * @return mixed
73
     */
74 1
    public static function remove($data, $keys)
75
    {
76 1
        return self::instance()->removeValue($data, $keys);
77
    }
78
79
    /**
80
     * @param mixed            $data
81
     * @param array|string|int $keys
82
     * @param mixed|null       $default
83
     *
84
     * @return mixed
85
     */
86 4
    public function getValue($data, $keys, $default = null)
87
    {
88 4
        if ($this->isKeysEmpty($keys)) {
89 1
            return $data;
90
        }
91 3
        if (!is_array($keys)) {
92 1
            $keys = [$keys];
93 1
        }
94
95 3
        $accessor = new Accessor($data);
96 3
        foreach ($keys as $key) {
97 3
            if ($accessor->to($key) === false) {
98 1
                return $default;
99
            }
100 2
        }
101
102 2
        return $accessor->getCurrent();
103
    }
104
105
    /**
106
     * @param mixed            $data
107
     * @param array|string|int $keys
108
     * @param mixed            $value
109
     *
110
     * @return mixed
111
     */
112 5 View Code Duplication
    public function setValue($data, $keys, $value)
0 ignored issues
show
This method seems to be duplicated in 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...
113
    {
114 5
        if ($this->isKeysEmpty($keys)) {
115 1
            return $data;
116
        }
117 4
        if (!is_array($keys)) {
118 1
            $keys = [$keys];
119 1
        }
120
121 4
        $accessor = new Accessor($data);
122 4
        $depth    = 0;
123 4
        $keyCount = count($keys);
124 4
        foreach ($keys as $key) {
125 4
            if ($depth + 1 === $keyCount) {
126 3
                if ($accessor->set($key, $value) === false) {
127 1
                    throw new InvalidArgumentException(sprintf(
128 1
                        'Did not set path %s in structure %s',
129 1
                        json_encode($keys),
130 1
                        json_encode($data)
131 1
                    ));
132
                }
133 4
            } elseif ($accessor->to($key) === false) {
134 1
                throw new InvalidArgumentException(sprintf(
135 1
                    'Did not find path %s in structure %s',
136 1
                    json_encode($keys),
137 1
                    json_encode($data)
138 1
                ));
139
            }
140
141 3
            ++$depth;
142 3
        }
143
144 2
        return $accessor->getData();
145
    }
146
147
    /**
148
     * @param mixed $data
149
     * @param array $keys
150
     *
151
     * @return bool
152
     */
153 4
    public function hasValue($data, $keys)
154
    {
155 4
        if ($this->isKeysEmpty($keys)) {
156 1
            return true;
157
        }
158 3
        if (!is_array($keys)) {
159 1
            $keys = [$keys];
160 1
        }
161
162 3
        $accessor = new Accessor($data);
163 3
        $keyCount = count($keys);
164 3
        $depth    = 0;
165 3
        foreach ($keys as $key) {
166 3
            if (($depth + 1 === $keyCount && $accessor->has($key) === false) || $accessor->to($key) === false) {
167 1
                return false;
168
            }
169
170 3
            ++$depth;
171 3
        }
172
173 2
        return true;
174
    }
175
176
    /**
177
     * @param mixed            $data
178
     * @param array|string|int $keys
179
     *
180
     * @return mixed
181
     */
182 5 View Code Duplication
    public function removeValue($data, $keys)
0 ignored issues
show
This method seems to be duplicated in 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...
183
    {
184 5
        if ($this->isKeysEmpty($keys)) {
185 1
            return;
186
        }
187 4
        if (!is_array($keys)) {
188 1
            $keys = [$keys];
189 1
        }
190
191 4
        $accessor = new Accessor($data);
192 4
        $keyCount = count($keys);
193 4
        $depth    = 0;
194 4
        foreach ($keys as $key) {
195 4
            if ($depth + 1 === $keyCount) {
196 3
                if ($accessor->remove($key) === false) {
197 1
                    throw new InvalidArgumentException(sprintf(
198 1
                        'Did not remove path %s in structure %s',
199 1
                        json_encode($keys),
200 1
                        json_encode($data)
201 1
                    ));
202
                }
203 4
            } elseif ($accessor->to($key) === false) {
204 1
                throw new InvalidArgumentException(sprintf(
205 1
                    'Did not find path %s in structure %s',
206 1
                    json_encode($keys),
207 1
                    json_encode($data)
208 1
                ));
209
            }
210
211 3
            ++$depth;
212 3
        }
213
214 2
        return $accessor->getData();
215
    }
216
217
    /**
218
     * @param string[]|string|null $keys
219
     *
220
     * @return bool
221
     */
222 1
    protected function isKeysEmpty($keys)
223
    {
224 1
        return $keys === null || $keys === '' || count($keys) === 0;
225
    }
226
}
227