Skip to content

Commit 13898d4

Browse files
Update Spl methods with side-effects
1 parent eda9ffd commit 13898d4

File tree

6 files changed

+111
-0
lines changed

6 files changed

+111
-0
lines changed

bin/functionMetadata_original.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@
170170
'DateTimeImmutable::getTimestamp' => ['hasSideEffects' => false],
171171
'DateTimeImmutable::getTimezone' => ['hasSideEffects' => false],
172172

173+
'SplDoublyLinkedList::pop' => ['hasSideEffects' => true],
174+
'SplDoublyLinkedList::shift' => ['hasSideEffects' => true],
175+
173176
'SplFileObject::fflush' => ['hasSideEffects' => true],
174177
'SplFileObject::fgetc' => ['hasSideEffects' => true],
175178
'SplFileObject::fgetcsv' => ['hasSideEffects' => true],
@@ -183,6 +186,24 @@
183186
'SplFileObject::ftruncate' => ['hasSideEffects' => true],
184187
'SplFileObject::fwrite' => ['hasSideEffects' => true],
185188

189+
'SplFixedArray::extract' => ['hasSideEffects' => true],
190+
191+
'SplHead::extract' => ['hasSideEffects' => true],
192+
'SplHead::insert' => ['hasSideEffects' => true],
193+
'SplHead::recoverFromCorruption' => ['hasSideEffects' => true],
194+
195+
'SplObjectStorage::addAll' => ['hasSideEffects' => true],
196+
'SplObjectStorage::attach' => ['hasSideEffects' => true],
197+
'SplObjectStorage::detach' => ['hasSideEffects' => true],
198+
'SplObjectStorage::removeAll' => ['hasSideEffects' => true],
199+
'SplObjectStorage::removeAllExcept' => ['hasSideEffects' => true],
200+
201+
'SplPriorityQueue::extract' => ['hasSideEffects' => true],
202+
'SplPriorityQueue::insert' => ['hasSideEffects' => true],
203+
'SplPriorityQueue::recoverFromCorruption' => ['hasSideEffects' => true],
204+
205+
'SplQueue::dequeue' => ['hasSideEffects' => true],
206+
186207
'XmlReader::next' => ['hasSideEffects' => true],
187208
'XmlReader::read' => ['hasSideEffects' => true],
188209
];

resources/functionMetadata.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@
639639
'SimpleXMLIterator::hasChildren' => ['hasSideEffects' => false],
640640
'SimpleXMLIterator::valid' => ['hasSideEffects' => false],
641641
'SoapFault::__construct' => ['hasSideEffects' => false],
642+
'SplDoublyLinkedList::pop' => ['hasSideEffects' => true],
643+
'SplDoublyLinkedList::shift' => ['hasSideEffects' => true],
642644
'SplFileObject::fflush' => ['hasSideEffects' => true],
643645
'SplFileObject::fgetc' => ['hasSideEffects' => true],
644646
'SplFileObject::fgetcsv' => ['hasSideEffects' => true],
@@ -651,6 +653,19 @@
651653
'SplFileObject::fseek' => ['hasSideEffects' => true],
652654
'SplFileObject::ftruncate' => ['hasSideEffects' => true],
653655
'SplFileObject::fwrite' => ['hasSideEffects' => true],
656+
'SplFixedArray::extract' => ['hasSideEffects' => true],
657+
'SplHead::extract' => ['hasSideEffects' => true],
658+
'SplHead::insert' => ['hasSideEffects' => true],
659+
'SplHead::recoverFromCorruption' => ['hasSideEffects' => true],
660+
'SplObjectStorage::addAll' => ['hasSideEffects' => true],
661+
'SplObjectStorage::attach' => ['hasSideEffects' => true],
662+
'SplObjectStorage::detach' => ['hasSideEffects' => true],
663+
'SplObjectStorage::removeAll' => ['hasSideEffects' => true],
664+
'SplObjectStorage::removeAllExcept' => ['hasSideEffects' => true],
665+
'SplPriorityQueue::extract' => ['hasSideEffects' => true],
666+
'SplPriorityQueue::insert' => ['hasSideEffects' => true],
667+
'SplPriorityQueue::recoverFromCorruption' => ['hasSideEffects' => true],
668+
'SplQueue::dequeue' => ['hasSideEffects' => true],
654669
'Spoofchecker::__construct' => ['hasSideEffects' => false],
655670
'StringBackedEnum::from' => ['hasSideEffects' => false],
656671
'StringBackedEnum::tryFrom' => ['hasSideEffects' => false],

tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ public function testBug9850(): void
245245
$this->analyse([__DIR__ . '/data/bug-9850.php'], []);
246246
}
247247

248+
public function testBug9180(): void
249+
{
250+
$this->treatPhpDocTypesAsCertain = true;
251+
$this->analyse([__DIR__ . '/data/bug-9180.php'], []);
252+
}
253+
248254
public function testBug12716(): void
249255
{
250256
$this->treatPhpDocTypesAsCertain = true;

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);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Bug9180;
4+
5+
$queue = new \SplQueue();
6+
7+
$queue->push(1);
8+
9+
if ($queue->count() > 0) {
10+
for ($i=0;$i<5;$i++) {
11+
while ($queue->count() > 0 && $value = $queue->shift()) {
12+
//do something with $value
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)