File tree Expand file tree Collapse file tree 3 files changed +60
-0
lines changed
tests/PHPStan/Rules/Comparison Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 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];
Original file line number Diff line number Diff 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 ' ], []);
Original file line number Diff line number Diff line change 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 );
You can’t perform that action at this time.
0 commit comments