Skip to content

Commit f9439c9

Browse files
Fix
1 parent 5878035 commit f9439c9

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

bin/functionMetadata_original.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@
183183
'SplFileObject::ftruncate' => ['hasSideEffects' => true],
184184
'SplFileObject::fwrite' => ['hasSideEffects' => true],
185185

186+
'SplObjectStorage::addAll' => ['hasSideEffects' => true],
187+
'SplObjectStorage::attach' => ['hasSideEffects' => true],
188+
'SplObjectStorage::detach' => ['hasSideEffects' => true],
189+
'SplObjectStorage::removeAll' => ['hasSideEffects' => true],
190+
'SplObjectStorage::removeAllExcept' => ['hasSideEffects' => true],
191+
186192
'XmlReader::next' => ['hasSideEffects' => true],
187193
'XmlReader::read' => ['hasSideEffects' => true],
188194
];

tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,11 @@ public function testBug12946(): void
996996
$this->analyse([__DIR__ . '/data/bug-12946.php'], []);
997997
}
998998

999+
public function testBug10884(): void
1000+
{
1001+
$this->analyse([__DIR__ . '/data/bug-10884.php'], []);
1002+
}
1003+
9991004
public function testBug13208(): void
10001005
{
10011006
$this->analyse([__DIR__ . '/data/bug-13208.php'], []);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug10884;
4+
5+
class Cat {}
6+
7+
/** @var \SplObjectStorage<Cat, null> $map */
8+
$map = new \SplObjectStorage();
9+
$map->attach(new Cat());
10+
$map->attach(new Cat());
11+
12+
class Manager
13+
{
14+
/**
15+
* @param SplObjectStorage<Cat, null> $map
16+
*/
17+
public function doSomething(\SplObjectStorage $map): void
18+
{
19+
/** @var \SplObjectStorage<Cat, null> $other */
20+
$other = new \SplObjectStorage();
21+
22+
if (count($map) === 0) {
23+
return;
24+
}
25+
26+
foreach ($map as $cat) {
27+
if (!$this->someCheck($cat)) {
28+
continue;
29+
}
30+
31+
$other->attach($cat);
32+
}
33+
34+
$map->removeAll($other);
35+
36+
if (count($map) === 0) {
37+
return;
38+
}
39+
40+
// ok!
41+
}
42+
43+
private function someCheck(Cat $cat): bool {
44+
// just some random
45+
return $cat == true;
46+
}
47+
}
48+
49+
(new Manager())->doSomething($map);

0 commit comments

Comments
 (0)