Issues (19)

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/ObjectBiMap.php (16 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 declare(strict_types=1);
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 22 and the first side effect is on line 166.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/*
4
 * This file is part of the pinepain/php-object-maps PHP library.
5
 *
6
 * Copyright (c) 2016-2017 Bogdan Padalko <[email protected]>
7
 *
8
 * Licensed under the MIT license: http://opensource.org/licenses/MIT
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code or visit http://opensource.org/licenses/MIT
12
 */
13
14
15
namespace Pinepain\ObjectMaps;
16
17
18
use Pinepain\ObjectMaps\Exceptions\OutOfBoundsException;
19
use Pinepain\ObjectMaps\Exceptions\OverflowException;
20
21
22
class ObjectBiMap implements ObjectBiMapInterface
23
{
24
    use ObjectTypeHintTrait;
25
26
    protected $behavior = self::DEFAULT;
27
28
    /**
29
     * @var ObjectMapInterface
30
     */
31
    protected $keys;
32
    /**
33
     * @var ObjectMapInterface
34
     */
35
    protected $values;
36
37
    /**
38
     * @param int $behavior
39
     */
40 22
    public function __construct(int $behavior = self::DEFAULT)
0 ignored issues
show
Possible parse error: non-abstract method defined as abstract
Loading history...
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
41
    {
42 22
        $key_behavior   = 0;
43 22
        $value_behavior = 0;
0 ignored issues
show
The visibility should be declared for property $value_behavior.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
44
45 22
        if ($behavior & self::WEAK_KEY) {
0 ignored issues
show
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
The visibility should be declared for property $behavior.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
46 5
            $key_behavior   |= self::WEAK_KEY;
47 5
            $value_behavior |= self::WEAK_VALUE;
0 ignored issues
show
The visibility should be declared for property $value_behavior.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
48
        }
49
50 22
        if ($behavior & self::WEAK_VALUE) {
0 ignored issues
show
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
The visibility should be declared for property $behavior.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
51 5
            $key_behavior   |= self::WEAK_VALUE;
52 5
            $value_behavior |= self::WEAK_KEY;
0 ignored issues
show
The visibility should be declared for property $value_behavior.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
53
        }
54
55 22
        $this->keys   = new ObjectMap($key_behavior);
0 ignored issues
show
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
The visibility should be declared for property $this.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
56 22
        $this->values = new ObjectMap($value_behavior);
0 ignored issues
show
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
The visibility should be declared for property $this.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
57
58 22
        $this->behavior = $behavior;
0 ignored issues
show
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
The visibility should be declared for property $this.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
59 22
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 4
    public function values(): ObjectBiMapInterface
65
    {
66 4
        $new_behavior = 0;
67
68 4
        if ($this->behavior & self::WEAK_KEY) {
69 2
            $new_behavior |= self::WEAK_VALUE;
70
        }
71
72 4
        if ($this->behavior & self::WEAK_VALUE) {
73 2
            $new_behavior |= self::WEAK_KEY;
74
        }
75
76 4
        $new = new static($new_behavior);
77
78 4
        $new->keys   = $this->values;
79 4
        $new->values = $this->keys;
80
81 4
        return $new;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87 17
    public function put($key, $value)
88
    {
89 17
        $this->assertObject($key, 'Key');
90
91 16
        if ($this->keys->has($key)) {
92 1
            throw new OverflowException('Value with such key already exists');
93
        }
94
95 16
        $this->assertObject($value, 'Value');
96
97 15
        if ($this->values->has($value)) {
98
            // UNEXPECTED
99 1
            throw new OverflowException('Key with such value already exists');
100
        }
101
102 14
        $this->keys->put($key, $value);
103 14
        $this->values->put($value, $key);
104 14
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109 3
    public function get($key)
110
    {
111 3
        $this->assertObject($key, 'Key');
112
113 2
        return $this->keys->get($key);
114
    }
115
116
    /**
117
     * {@inheritdoc}
118
     */
119
120 6
    public function has($key): bool
121
    {
122 6
        $this->assertObject($key, 'Key');
123
124 5
        return $this->keys->has($key);
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130 5
    public function remove($key)
131
    {
132 5
        $this->assertObject($key, 'Key');
133
134 4
        if (!$this->keys->has($key)) {
135 1
            throw new OutOfBoundsException('Value with such key not found');
136
        }
137
138 3
        $value = $this->keys->remove($key);
139
140 3
        if (!$this->values->has($value)) {
141
            // UNEXPECTED
142 1
            throw new OutOfBoundsException('Key with such value not found');
143
        }
144
145 2
        $this->values->remove($value);
146
147 2
        return $value;
148
    }
149
150
    /**
151
     * {@inheritdoc}
152
     */
153 10
    public function count()
154
    {
155 10
        return count($this->keys);
156
    }
157
158
    /**
159
     * {@inheritdoc}
160
     */
161 2
    public function clear()
162
    {
163 2
        $this->keys->clear();
164 2
        $this->values->clear();
165 2
    }
166
}
167