Skip to content

Commit 3f52cfb

Browse files
committed
Support method calls / static calls
1 parent ddb0a5c commit 3f52cfb

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,7 @@ static function (): void {
28512851

28522852
if ($parametersAcceptor !== null) {
28532853
$expr = ArgumentsNormalizer::reorderMethodArguments($parametersAcceptor, $expr) ?? $expr;
2854+
$isAlwaysTerminating = $parametersAcceptor->getReturnType() instanceof NeverType;
28542855
}
28552856

28562857
$result = $this->processArgs(
@@ -3037,6 +3038,7 @@ static function (): void {
30373038

30383039
if ($parametersAcceptor !== null) {
30393040
$expr = ArgumentsNormalizer::reorderStaticCallArguments($parametersAcceptor, $expr) ?? $expr;
3041+
$isAlwaysTerminating = $parametersAcceptor->getReturnType() instanceof NeverType;
30403042
}
30413043
$result = $this->processArgs($stmt, $methodReflection, null, $parametersAcceptor, $expr, $scope, $nodeCallback, $context, $closureBindScope ?? null);
30423044
$scope = $result->getScope();

tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,19 @@ public function testBug13232b(): void
262262
]);
263263
}
264264

265+
public function testBug13232c(): void
266+
{
267+
$this->treatPhpDocTypesAsCertain = false;
268+
$this->analyse([__DIR__ . '/data/bug-13232c.php'], [
269+
[
270+
'Unreachable statement - code above always terminates.',
271+
12,
272+
],
273+
[
274+
'Unreachable statement - code above always terminates.',
275+
20,
276+
],
277+
]);
278+
}
279+
265280
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Bug13232c;
4+
5+
final class HelloWorld
6+
{
7+
public function sayHello(): void
8+
{
9+
echo 'Hello, ' . $this->mightReturnNever()
10+
. ' no way';
11+
12+
echo 'this will never happen';
13+
}
14+
15+
static public function sayStaticHello(): void
16+
{
17+
echo 'Hello, ' . self::staticMightReturnNever()
18+
. ' no way';
19+
20+
echo 'this will never happen';
21+
}
22+
23+
function mightReturnNever(): never
24+
25+
{
26+
exit();
27+
}
28+
29+
static function staticMightReturnNever(): never
30+
{
31+
exit();
32+
}
33+
34+
}

0 commit comments

Comments
 (0)