Skip to content

Commit 8b1d78d

Browse files
Mikulas Bacinskyondrejmirtes
authored andcommitted
feat: improve Map::remove() @throws inference
1 parent 7755854 commit 8b1d78d

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/Type/Php/DsMapDynamicMethodThrowTypeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class DsMapDynamicMethodThrowTypeExtension implements DynamicMethodThrowTy
1616
public function isMethodSupported(MethodReflection $methodReflection): bool
1717
{
1818
return $methodReflection->getDeclaringClass()->getName() === 'Ds\Map'
19-
&& $methodReflection->getName() === 'get';
19+
&& ($methodReflection->getName() === 'get' || $methodReflection->getName() === 'remove');
2020
}
2121

2222
public function getThrowTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type|null

tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function testBug9066(): void
202202
$this->analyse([__DIR__ . '/data/bug-9066.php'], [
203203
[
204204
'Dead catch - OutOfBoundsException is never thrown in the try block.',
205-
19,
205+
28,
206206
],
207207
]);
208208
}

tests/PHPStan/Rules/Exceptions/data/bug-9066.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,27 @@
44

55
class Foo
66
{
7-
public function mayThrow()
7+
public function getMayThrow()
88
{ $map = new \Ds\Map();
99
try {
1010
$map->get('1');
1111
} catch (\OutOfBoundsException $e) {
1212

1313
}
1414
}
15+
public function removeMayThrow()
16+
{ $map = new \Ds\Map();
17+
try {
18+
$map->remove('1');
19+
} catch (\OutOfBoundsException $e) {
20+
21+
}
22+
}
1523
public function neverThrows()
1624
{ $map = new \Ds\Map();
1725
try {
1826
$map->get('1', null);
27+
$map->remove('1', null);
1928
} catch (\OutOfBoundsException $e) {
2029

2130
}

0 commit comments

Comments
 (0)