Issues (25)

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/AppserverIo/Collections/HashMap.php (3 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
 * \AppserverIo\Collections\HashMap
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/collections
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Collections;
22
23
use \AppserverIo\Lang\Strng;
24
use \AppserverIo\Lang\Integer;
25
use \AppserverIo\Lang\Flt;
26
use \AppserverIo\Lang\Boolean;
27
use \AppserverIo\Lang\NullPointerException;
28
use \AppserverIo\Lang\ClassCastException;
29
30
/**
31
 * This class is the implementation of a HashMap.
32
 *
33
 * @author    Tim Wagner <[email protected]>
34
 * @copyright 2015 TechDivision GmbH <[email protected]>
35
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
36
 * @link      https://github.com/appserver-io/collections
37
 * @link      http://www.appserver.io
38
 */
39
class HashMap extends AbstractMap
40
{
41
42
    /**
43
     * Standard constructor that adds the array passed
44
     * as parameter to the internal member variable.
45
     *
46
     * @param array $items An array to initialize the HashMap
47
     *
48
     * @throws \AppserverIo\Lang\ClassCastException Is thrown if the passed parameter is not of type array
49
     */
50 5 View Code Duplication
    public function __construct($items = array())
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...
51
    {
52
        // parent constructor to ensure property preset
53 5
        parent::__construct();
54
55
        // check if NULL is passed, is yes, to nothing
56 5
        if (is_null($items)) {
57
            return;
58
        }
59
        // check if an array is passed
60 5
        if (is_array($items)) {
61
            // initialize the HashMap with the values of the passed array
62 5
            foreach ($items as $key => $item) {
63
                $this->add($key, $item);
64 5
            }
65 5
            return;
66
        }
67
        // if not a array is passed throw an exception
68
        throw new ClassCastException('Passed object is not an array');
69
    }
70
71
    /**
72
     * This method adds the passed object with the passed key
73
     * to the HashMap.
74
     *
75
     * @param mixed $key    The key to add the passed value under
76
     * @param mixed $object The object to add to the HashMap
77
     *
78
     * @return \AppserverIo\Collections\HashMap The instance
79
     * @throws \AppserverIo\Collections\InvalidKeyException Is thrown if the passed key is NOT an primitive datatype
80
     * @throws \AppserverIo\Lang\NullPointerException Is thrown if the passed key is null or not a flat datatype like Integer, Strng, Double or Boolean
81
     */
82 3
    public function add($key, $object)
83
    {
84 3
        if (is_null($key)) {
85
            throw new NullPointerException('Passed key is null');
86
        }
87
        // check if a primitive datatype is passed
88 3 View Code Duplication
        if (is_integer($key) || is_string($key) || is_double($key) || is_bool($key)) {
0 ignored issues
show
This code seems to be duplicated across 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...
89
            // add the item to the array
90 3
            $this->items[$key] = $object;
91
            // and return
92 3
            return;
93
        }
94
        // check if an object is passed
95 View Code Duplication
        if (is_object($key)) {
0 ignored issues
show
This code seems to be duplicated across 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...
96
            if ($key instanceof Strng) {
97
                $newKey = $key->stringValue();
98
            } elseif ($key instanceof Flt) {
99
                $newKey = $key->floatValue();
100
            } elseif ($key instanceof Integer) {
101
                $newKey = $key->intValue();
102
            } elseif ($key instanceof Boolean) {
103
                $newKey = $key->booleanValue();
104
            } elseif (method_exists($key, '__toString')) {
105
                $newKey = $key->__toString();
106
            } else {
107
                throw new InvalidKeyException('Passed key has to be a primitive datatype or  has to implement the __toString() method');
108
            }
109
            // add the item to the array
110
            $this->items[$newKey] = $object;
111
            // and return
112
            return;
113
        }
114
        throw new InvalidKeyException('Passed key has to be a primitive datatype or  has to implement the __toString() method');
115
    }
116
117
    /**
118
     * This method Returns a new HashMap initialized with the
119
     * passed array.
120
     *
121
     * @param array $array Holds the array to initialize the new HashMap
122
     *
123
     * @return \AppserverIo\Collections\HashMap Returns a HashMap initialized with the passed array
124
     * @throws \AppserverIo\Lang\ClassCastException Is thrown if the passed object is not an array
125
     */
126
    public static function fromArray($array)
127
    {
128
        // check if the passed object is an array and set it
129
        if (is_array($array)) {
130
            return new HashMap($array);
131
        }
132
        // throw an exception if the passed object is not an array
133
        throw new ClassCastException('Passed object is not an array');
134
    }
135
}
136