Issues (40)

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/ArrayStore.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
/*
4
 * This file is part of the webmozart/key-value-store package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webmozart\KeyValueStore;
13
14
use Webmozart\KeyValueStore\Api\CountableStore;
15
use Webmozart\KeyValueStore\Api\NoSuchKeyException;
16
use Webmozart\KeyValueStore\Api\SortableStore;
17
use Webmozart\KeyValueStore\Util\KeyUtil;
18
19
/**
20
 * A key-value store backed by a PHP array.
21
 *
22
 * The contents of the store are lost when the store is released from memory.
23
 *
24
 * @since  1.0
25
 *
26
 * @author Bernhard Schussek <[email protected]>
27
 */
28
class ArrayStore implements SortableStore, CountableStore
29
{
30
    /**
31
     * Flag: Enable serialization.
32
     */
33
    const SERIALIZE = 1;
34
35
    /**
36
     * @var array
37
     */
38
    private $array = array();
39
40
    /**
41
     * @var callable
42
     */
43
    private $serialize;
44
45
    /**
46
     * @var callable
47
     */
48
    private $unserialize;
49
50
    /**
51
     * Creates a new store.
52
     *
53
     * @param array $array The values to set initially in the store.
54
     */
55 192
    public function __construct(array $array = array(), $flags = 0)
56
    {
57 192
        if ($flags & self::SERIALIZE) {
58 93
            $this->serialize = array(
59
                'Webmozart\KeyValueStore\Util\Serializer',
60
                'serialize',
61
            );
62 93
            $this->unserialize = array(
63 93
                'Webmozart\KeyValueStore\Util\Serializer',
64
                'unserialize',
65
            );
66
        } else {
67
            $this->serialize = function ($value) {
68 67
                return $value;
69
            };
70 45
            $this->unserialize = function ($value) {
71 45
                return $value;
72
            };
73
        }
74
75 192
        foreach ($array as $key => $value) {
76 2
            $this->set($key, $value);
77
        }
78 192
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 132
    public function set($key, $value)
84
    {
85 132
        KeyUtil::validate($key);
86
87 128
        $this->array[$key] = call_user_func($this->serialize, $value);
88 128
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93 12 View Code Duplication
    public function get($key, $default = null)
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...
94
    {
95 12
        KeyUtil::validate($key);
96
97 8
        if (!array_key_exists($key, $this->array)) {
98 2
            return $default;
99
        }
100
101 6
        return call_user_func($this->unserialize, $this->array[$key]);
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107 60 View Code Duplication
    public function getOrFail($key)
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...
108
    {
109 60
        KeyUtil::validate($key);
110
111 56
        if (!array_key_exists($key, $this->array)) {
112 2
            throw NoSuchKeyException::forKey($key);
113
        }
114
115 54
        return call_user_func($this->unserialize, $this->array[$key]);
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121 80
    public function getMultiple(array $keys, $default = null)
122
    {
123 80
        KeyUtil::validateMultiple($keys);
124
125 76
        $values = array();
126
127 76
        foreach ($keys as $key) {
128 76
            $values[$key] = array_key_exists($key, $this->array)
129 76
                ? call_user_func($this->unserialize, $this->array[$key])
130 76
                : $default;
131
        }
132
133 76
        return $values;
134
    }
135
136
    /**
137
     * {@inheritdoc}
138
     */
139 60
    public function getMultipleOrFail(array $keys)
140
    {
141 60
        KeyUtil::validateMultiple($keys);
142
143 56
        $notFoundKeys = array_diff($keys, array_keys($this->array));
144
145 56
        if (count($notFoundKeys) > 0) {
146 2
            throw NoSuchKeyException::forKeys($notFoundKeys);
147
        }
148
149 54
        return $this->getMultiple($keys);
150
    }
151
152
    /**
153
     * {@inheritdoc}
154
     */
155 20
    public function remove($key)
156
    {
157 20
        KeyUtil::validate($key);
158
159 16
        $removed = array_key_exists($key, $this->array);
160
161 16
        unset($this->array[$key]);
162
163 16
        return $removed;
164
    }
165
166
    /**
167
     * {@inheritdoc}
168
     */
169 60
    public function exists($key)
170
    {
171 60
        KeyUtil::validate($key);
172
173 56
        return array_key_exists($key, $this->array);
174
    }
175
176
    /**
177
     * {@inheritdoc}
178
     */
179 186
    public function clear()
180
    {
181 186
        $this->array = array();
182 186
    }
183
184
    /**
185
     * {@inheritdoc}
186
     */
187 24
    public function keys()
188
    {
189 24
        return array_keys($this->array);
190
    }
191
192
    /**
193
     * Returns the contents of the store as array.
194
     *
195
     * @return array The keys and values in the store.
196
     */
197
    public function toArray()
198
    {
199
        return array_map($this->unserialize, $this->array);
200
    }
201
202
    /**
203
     * {@inheritdoc}
204
     */
205 12
    public function sort($flags = SORT_REGULAR)
206
    {
207 12
        ksort($this->array, $flags);
208 12
    }
209
210
    /**
211
     * {@inheritdoc}
212
     */
213 2
    public function count()
214
    {
215 2
        return count($this->array);
216
    }
217
}
218