Skip to content

Commit b8fbca7

Browse files
committed
Support method calls / static calls
1 parent 22b893a commit b8fbca7

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
@@ -2852,6 +2852,7 @@ static function (): void {
28522852

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

28572858
$result = $this->processArgs(
@@ -3038,6 +3039,7 @@ static function (): void {
30383039

30393040
if ($parametersAcceptor !== null) {
30403041
$expr = ArgumentsNormalizer::reorderStaticCallArguments($parametersAcceptor, $expr) ?? $expr;
3042+
$isAlwaysTerminating = $parametersAcceptor->getReturnType() instanceof NeverType;
30413043
}
30423044
$result = $this->processArgs($stmt, $methodReflection, null, $parametersAcceptor, $expr, $scope, $nodeCallback, $context, $closureBindScope ?? null);
30433045
$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)