This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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
|
|||
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
|
|||
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. ![]() |
|||
44 | |||
45 | 22 | if ($behavior & self::WEAK_KEY) { |
|
0 ignored issues
–
show
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. ![]() |
|||
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. ![]() |
|||
48 | } |
||
49 | |||
50 | 22 | if ($behavior & self::WEAK_VALUE) { |
|
0 ignored issues
–
show
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. ![]() |
|||
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. ![]() |
|||
53 | } |
||
54 | |||
55 | 22 | $this->keys = new ObjectMap($key_behavior); |
|
0 ignored issues
–
show
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. ![]() |
|||
56 | 22 | $this->values = new ObjectMap($value_behavior); |
|
0 ignored issues
–
show
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. ![]() |
|||
57 | |||
58 | 22 | $this->behavior = $behavior; |
|
0 ignored issues
–
show
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. ![]() |
|||
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 |
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.