Issues (15)

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/Map/HashMap.php (5 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 namespace BuildR\Collection\Map;
2
3
use BuildR\Collection\ArrayList\ArrayList;
4
use BuildR\Collection\Collection\AbstractTypedCollection;
5
use BuildR\Collection\Collection\FilterableCollectionTrait;
6
use BuildR\Collection\Exception\MapException;
7
use BuildR\Collection\Set\HashSet;
8
9
/**
10
 * MapInterface implementation
11
 *
12
 * BuildR PHP Framework
13
 *
14
 * @author Zoltán Borsos <[email protected]>
15
 * @package Collection
16
 * @subpackage Map
17
 *
18
 * @copyright    Copyright 2015, Zoltán Borsos.
19
 * @license      https://github.com/Zolli/BuildR/blob/master/LICENSE.md
20
 * @link         https://github.com/Zolli/BuildR
21
 */
22
class HashMap extends AbstractTypedCollection implements MapInterface {
23
24
    use FilterableCollectionTrait;
25
26
    /**
27
     * HashMap constructor.
28
     *
29
     * @param array|null $content
30
     */
31 58
    public function __construct($content = NULL) {
32 58
        if($content !== NULL && is_array($content)) {
33 6
            $this->putAll($content);
34 6
        }
35 58
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40 54
    public function containsKey($key) {
41 54
        $this->checkKeyType($key);
42
43 54
        return isset($this->data[$key]);
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49 4
    public function containsValue($value) {
50 4
        return (array_search($value, $this->data, TRUE) === FALSE) ? FALSE : TRUE;
51
    }
52
53
    /**
54
     * {@inheritDoc}
55
     */
56 24
    public function contains($key, $value) {
57 24
        if(isset($this->data[$key]) && $this->data[$key] === $value) {
58 24
            return TRUE;
59
        }
60
61 12
        return FALSE;
62
    }
63
64
    /**
65
     * {@inheritDoc}
66
     */
67 12
    public function equals(MapInterface $map) {
68 12
        if($this->size() !== $map->size()) {
69 4
            return FALSE;
70
        }
71
72 12
        foreach($this->data as $key => $value) {
73 12
            if(!$map->contains($key, $value)) {
74 4
                return FALSE;
75
            }
76 12
        }
77
78 12
        return TRUE;
79
    }
80
81
    /**
82
     * {@inheritDoc}
83
     */
84 8
    public function each(callable $callback) {
85 8
        foreach($this->data as $key => $value) {
86 8
            call_user_func_array($callback, [$key, $value]);
87 8
        }
88 8
    }
89
90
    /**
91
     * {@inheritDoc}
92
     */
93 28 View Code Duplication
    public function get($key, $defaultValue = 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 28
        $this->checkKeyType($key);
95
96 28
        if(!$this->containsKey($key)) {
97 4
            return $defaultValue;
98
        }
99
100 28
        return $this->data[$key];
101
    }
102
103
    /**
104
     * {@inheritDoc}
105
     */
106 4
    public function keySet() {
107 4
        return new HashSet(array_keys($this->data));
108
    }
109
110
    /**
111
     * {@inheritDoc}
112
     */
113 4
    public function valueList() {
114 4
        return new ArrayList(array_values($this->data));
115
    }
116
117
    /**
118
     * {@inheritDoc}
119
     */
120 4
    public function merge(MapInterface $map) {
121 4
        $self = $this;
122
123 4
        $map->each(function($key, $value) use($self) {
124 4
            if(!$self->containsKey($key)) {
125 4
                $self->put($key, $value);
126 4
            }
127 4
        });
128 4
    }
129
130
    /**
131
     * {@inheritDoc}
132
     */
133 54 View Code Duplication
    public function put($key, $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...
134 54
        $this->doTypeCheck($value);
135 54
        $this->checkKeyType($key);
136 54
        $return = NULL;
137
138 54
        if($this->containsKey($key)) {
139 4
            $return = $this->get($key);
140 4
        }
141
142 54
        $this->data[$key] = $value;
143
144 54
        return $return;
145
    }
146
147
    /**
148
     * {@inheritDoc}
149
     */
150 46
    public function putAll($map) {
151 46
        if($map instanceof MapInterface) {
152 4
            $map = $map->toArray();
153 4
        }
154
155 46
        foreach($map as $key => $value) {
156 46
            $this->put($key, $value);
157 46
        }
158 46
    }
159
160
    /**
161
     * {@inheritDoc}
162
     */
163 4 View Code Duplication
    public function putIfAbsent($key, $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...
164 4
        $this->checkKeyType($key);
165
166 4
        if($this->containsKey($key)) {
167 4
            return $this->get($key);
168
        }
169
170 4
        $this->put($key, $value);
171
172 4
        return NULL;
173
    }
174
175
    /**
176
     * {@inheritDoc}
177
     */
178 4 View Code Duplication
    public function remove($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...
179 4
        $this->checkKeyType($key);
180
181 4
        if($this->containsKey($key)) {
182 4
            $previousElement = $this->get($key);
183 4
            unset($this->data[$key]);
184
185 4
            return $previousElement;
186
        }
187
188 4
        return NULL;
189
    }
190
191
    /**
192
     * {@inheritDoc}
193
     */
194 4
    public function removeIf($key, $value) {
195 4
        $this->checkKeyType($key);
196
197 4
        if($this->contains($key, $value)) {
198 4
            $previousElement = $this->get($key);
199 4
            unset($this->data[$key]);
200
201 4
            return $previousElement;
202
        }
203
204 4
        return NULL;
205
    }
206
207
    /**
208
     * {@inheritDoc}
209
     */
210 4 View Code Duplication
    public function replace($key, $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...
211 4
        $this->doTypeCheck($value);
212 4
        $this->checkKeyType($key);
213
214 4
        if($this->containsKey($key)) {
215 4
            $previousValue = $this->get($key);
216 4
            $this->data[$key] = $value;
217
218 4
            return $previousValue;
219
        }
220
221 4
        return NULL;
222
    }
223
224
    /**
225
     * {@inheritDoc}
226
     */
227 4
    public function replaceIf($key, $oldValue, $newValue) {
228 4
        $this->checkKeyType($key);
229
230 4
        if($this->contains($key, $oldValue)) {
231 4
            $previousValue = $this->get($key);
232 4
            $this->data[$key] = $newValue;
233
234 4
            return $previousValue;
235
        }
236
237 4
        return NULL;
238
    }
239
240
    /**
241
     * Validate the given key. This map only allows scalar types
242
     * as items key. If the validation is fails, throws a MapException.
243
     *
244
     * @param mixed $key
245
     *
246
     * @return bool
247
     *
248
     * @throws \BuildR\Collection\Exception\MapException
249
     */
250 58
    protected function checkKeyType($key) {
251 58
        if(is_scalar($key)) {
252 54
            return TRUE;
253
        }
254
255 4
        throw MapException::notValidKey($key);
256
    }
257
258
}
259