pinepain /
php-object-maps
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\Tests; |
||
| 16 | |||
| 17 | |||
| 18 | use Pinepain\ObjectMaps\ObjectBiMap; |
||
| 19 | use Pinepain\ObjectMaps\ObjectBiMapInterface; |
||
| 20 | use Pinepain\ObjectMaps\ObjectMapInterface; |
||
| 21 | use Ref\WeakReference; |
||
| 22 | use SebastianBergmann\CodeCoverage\Report\PHP; |
||
| 23 | use stdClass; |
||
| 24 | |||
| 25 | |||
| 26 | class ObjectBiMapTest extends AbstractObjectMapInterfaceTest |
||
| 27 | { |
||
| 28 | public function buildMap(int $behavior = ObjectMapInterface::DEFAULT) |
||
|
0 ignored issues
–
show
|
|||
| 29 | { |
||
| 30 | return new ObjectBiMap($behavior); |
||
| 31 | } |
||
| 32 | |||
| 33 | public function testValuesForRegularMap() |
||
| 34 | { |
||
| 35 | $map = $this->buildMap(); |
||
| 36 | |||
| 37 | $key = new stdClass(); |
||
| 38 | $value = new stdClass(); |
||
| 39 | |||
| 40 | $map->put($key, $value); |
||
| 41 | |||
| 42 | $this->assertTrue($map->has($key)); |
||
| 43 | $this->assertFalse($map->has($value)); |
||
| 44 | |||
| 45 | $vmap = $map->values(); |
||
| 46 | |||
| 47 | $this->assertInstanceOf(ObjectBiMapInterface::class, $vmap); |
||
| 48 | |||
| 49 | $this->assertFalse($vmap->has($key)); |
||
| 50 | $this->assertTrue($vmap->has($value)); |
||
| 51 | |||
| 52 | $map->clear(); |
||
| 53 | |||
| 54 | $this->assertSame(0, $map->count()); |
||
| 55 | $this->assertSame(0, $vmap->count()); |
||
| 56 | |||
| 57 | $vmap->put($key, $value); |
||
| 58 | |||
| 59 | $this->assertSame(1, $vmap->count()); |
||
| 60 | $this->assertSame(1, $map->count()); |
||
| 61 | |||
| 62 | $this->assertFalse($map->has($key)); |
||
| 63 | $this->assertTrue($map->has($value)); |
||
| 64 | |||
| 65 | $key = null; |
||
|
0 ignored issues
–
show
$key is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 66 | $this->assertSame(1, $vmap->count()); |
||
| 67 | $this->assertSame(1, $map->count()); |
||
| 68 | |||
| 69 | $value = null; |
||
|
0 ignored issues
–
show
$value is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 70 | $this->assertSame(1, $vmap->count()); |
||
| 71 | $this->assertSame(1, $map->count()); |
||
| 72 | } |
||
| 73 | |||
| 74 | public function testValuesForWeakKeyMap() |
||
| 75 | { |
||
| 76 | $map = $this->buildMap(ObjectBiMapInterface::WEAK_KEY); |
||
| 77 | |||
| 78 | $key = new stdClass(); |
||
| 79 | $value = new stdClass(); |
||
| 80 | |||
| 81 | $map->put($key, $value); |
||
| 82 | |||
| 83 | $this->assertSame(1, $map->count()); |
||
| 84 | |||
| 85 | $vmap = $map->values(); |
||
| 86 | |||
| 87 | $this->assertInstanceOf(ObjectBiMapInterface::class, $vmap); |
||
| 88 | |||
| 89 | $this->assertFalse($vmap->has($key)); |
||
| 90 | $this->assertTrue($vmap->has($value)); |
||
| 91 | |||
| 92 | $this->assertSame(1, $map->count()); |
||
| 93 | $this->assertSame(1, $vmap->count()); |
||
| 94 | |||
| 95 | $value = null; |
||
|
0 ignored issues
–
show
$value is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 96 | $this->assertSame(1, $map->count()); |
||
| 97 | $this->assertSame(1, $vmap->count()); |
||
| 98 | |||
| 99 | $key = null; |
||
|
0 ignored issues
–
show
$key is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 100 | $this->assertSame(0, $map->count()); |
||
| 101 | $this->assertSame(0, $vmap->count()); |
||
| 102 | |||
| 103 | $key = new stdClass(); |
||
| 104 | $value = new stdClass(); |
||
| 105 | |||
| 106 | $vmap->put($key, $value); |
||
| 107 | |||
| 108 | $this->assertSame(1, $map->count()); |
||
| 109 | $this->assertSame(1, $vmap->count()); |
||
| 110 | |||
| 111 | $key = null; |
||
|
0 ignored issues
–
show
$key is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 112 | $this->assertSame(1, $map->count()); |
||
| 113 | $this->assertSame(1, $vmap->count()); |
||
| 114 | |||
| 115 | $value = null; |
||
|
0 ignored issues
–
show
$value is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 116 | $this->assertSame(0, $map->count()); |
||
| 117 | $this->assertSame(0, $vmap->count()); |
||
| 118 | } |
||
| 119 | |||
| 120 | public function testValuesForWeakValueMap() |
||
| 121 | { |
||
| 122 | $map = $this->buildMap(ObjectBiMapInterface::WEAK_VALUE); |
||
| 123 | |||
| 124 | $key = new stdClass(); |
||
| 125 | $value = new stdClass(); |
||
| 126 | |||
| 127 | $map->put($key, $value); |
||
| 128 | |||
| 129 | $this->assertSame(1, $map->count()); |
||
| 130 | |||
| 131 | $vmap = $map->values(); |
||
| 132 | |||
| 133 | $this->assertInstanceOf(ObjectBiMapInterface::class, $vmap); |
||
| 134 | |||
| 135 | $this->assertSame(1, $map->count()); |
||
| 136 | $this->assertSame(1, $vmap->count()); |
||
| 137 | |||
| 138 | $key = null; |
||
|
0 ignored issues
–
show
$key is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 139 | $this->assertSame(1, $map->count()); |
||
| 140 | $this->assertSame(1, $vmap->count()); |
||
| 141 | |||
| 142 | $value = null; |
||
|
0 ignored issues
–
show
$value is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 143 | $this->assertSame(0, $map->count()); |
||
| 144 | $this->assertSame(0, $vmap->count()); |
||
| 145 | |||
| 146 | $key = new stdClass(); |
||
| 147 | $value = new stdClass(); |
||
| 148 | |||
| 149 | $vmap->put($key, $value); |
||
| 150 | |||
| 151 | $this->assertSame(1, $map->count()); |
||
| 152 | $this->assertSame(1, $vmap->count()); |
||
| 153 | |||
| 154 | $value = null; |
||
|
0 ignored issues
–
show
$value is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 155 | $this->assertSame(1, $map->count()); |
||
| 156 | $this->assertSame(1, $vmap->count()); |
||
| 157 | |||
| 158 | $key = null; |
||
|
0 ignored issues
–
show
$key is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 159 | $this->assertSame(0, $map->count()); |
||
| 160 | $this->assertSame(0, $vmap->count()); |
||
| 161 | } |
||
| 162 | |||
| 163 | |||
| 164 | public function testValuesForWeakKeyValueMap() |
||
| 165 | { |
||
| 166 | // $map = $this->buildMap(ObjectBiMapInterface::WEAK_KEY_VALUE); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
50% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 167 | |||
| 168 | $map = new ObjectBiMap(ObjectBiMapInterface::WEAK_KEY_VALUE); |
||
| 169 | |||
| 170 | $key_1 = new stdClass(); |
||
| 171 | $value_1 = new stdClass(); |
||
| 172 | |||
| 173 | $key_2 = new stdClass(); |
||
| 174 | $value_2 = new stdClass(); |
||
| 175 | |||
| 176 | $map->put($key_1, $value_1); |
||
| 177 | echo PHP_EOL; |
||
| 178 | $map->put($key_2, $value_2); |
||
| 179 | echo PHP_EOL; |
||
| 180 | |||
| 181 | $this->assertSame(2, $map->count()); |
||
| 182 | |||
| 183 | $vmap = $map->values(); |
||
| 184 | |||
| 185 | $this->assertInstanceOf(ObjectBiMapInterface::class, $vmap); |
||
| 186 | |||
| 187 | $this->assertSame(2, $map->count()); |
||
| 188 | $this->assertSame(2, $vmap->count()); |
||
| 189 | |||
| 190 | $key_1 = null; |
||
|
0 ignored issues
–
show
$key_1 is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 191 | $this->assertSame(1, $map->count()); |
||
| 192 | $this->assertSame(1, $vmap->count()); |
||
| 193 | |||
| 194 | echo PHP_EOL; |
||
| 195 | |||
| 196 | $value_2 = null; |
||
|
0 ignored issues
–
show
$value_2 is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 197 | $this->assertSame(0, $map->count()); |
||
| 198 | $this->assertSame(0, $vmap->count()); |
||
| 199 | |||
| 200 | echo PHP_EOL; |
||
| 201 | |||
| 202 | $key_1 = new stdClass(); |
||
| 203 | $value_1 = new stdClass(); |
||
| 204 | |||
| 205 | $key_2 = new stdClass(); |
||
| 206 | $value_2 = new stdClass(); |
||
| 207 | |||
| 208 | $vmap->put($key_1, $value_1); |
||
| 209 | echo PHP_EOL; |
||
| 210 | |||
| 211 | $vmap->put($key_2, $value_2); |
||
| 212 | echo PHP_EOL; |
||
| 213 | |||
| 214 | $this->assertSame(2, $map->count()); |
||
| 215 | $this->assertSame(2, $vmap->count()); |
||
| 216 | |||
| 217 | $key_1 = null; |
||
|
0 ignored issues
–
show
$key_1 is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 218 | // $value_1 = null; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
43% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 219 | $this->assertSame(1, $map->count()); |
||
| 220 | $this->assertSame(1, $vmap->count()); |
||
| 221 | |||
| 222 | // $key_2 = null; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
43% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 223 | // var_dump(1); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 224 | $value_2 = null; |
||
|
0 ignored issues
–
show
$value_2 is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 225 | // debug_zval_dump($key_2); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 226 | // debug_zval_dump($value_2); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 227 | // var_dump(2); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 228 | // debug_zval_dump($map); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 229 | // debug_zval_dump($vmap); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 230 | $this->assertSame(0, $map->count()); |
||
| 231 | $this->assertSame(0, $vmap->count()); |
||
| 232 | } |
||
| 233 | |||
| 234 | public function testWeakRef() |
||
| 235 | { |
||
| 236 | $key_1 = new stdClass(); |
||
| 237 | $key_2 = new stdClass(); |
||
| 238 | $key_3 = new stdClass(); |
||
| 239 | $key_4 = new stdClass(); |
||
| 240 | |||
| 241 | $wr1 = new WeakReference($key_1, function () { |
||
|
0 ignored issues
–
show
$key_1 is of type object<stdClass>, but the function expects a object<Ref\object>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$wr1 is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 242 | echo 'Removing 1', PHP_EOL; |
||
| 243 | }); |
||
| 244 | |||
| 245 | $wr2 = new WeakReference($key_2, function () { |
||
|
0 ignored issues
–
show
$key_2 is of type object<stdClass>, but the function expects a object<Ref\object>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$wr2 is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 246 | echo 'Removing 2', PHP_EOL; |
||
| 247 | }); |
||
| 248 | |||
| 249 | $wr3 = new WeakReference($key_3, function () { |
||
|
0 ignored issues
–
show
$key_3 is of type object<stdClass>, but the function expects a object<Ref\object>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$wr3 is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 250 | echo 'Removing 3', PHP_EOL; |
||
| 251 | }); |
||
| 252 | |||
| 253 | $wr4 = new WeakReference($key_4, function () { |
||
|
0 ignored issues
–
show
$key_4 is of type object<stdClass>, but the function expects a object<Ref\object>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$wr4 is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 254 | echo 'Removing 4', PHP_EOL; |
||
| 255 | }); |
||
| 256 | } |
||
| 257 | |||
| 258 | } |
||
| 259 |
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.