Skip to content

Commit 08b4eab

Browse files
committed
Fixed false-negative with checkExplicitMixedMissingReturn: true
1 parent a97bdea commit 08b4eab

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/Rules/Missing/MissingReturnRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function processNode(Node $node, Scope $scope): array
6666
}
6767

6868
$isVoidSuperType = $returnType->isSuperTypeOf(new VoidType());
69-
if ($isVoidSuperType->yes()) {
69+
if ($isVoidSuperType->yes() && !$returnType instanceof MixedType) {
7070
return [];
7171
}
7272

tests/PHPStan/Rules/Missing/MissingReturnRuleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,15 @@ public function testBug2875(): void
116116
$this->analyse([__DIR__ . '/data/bug-2875.php'], []);
117117
}
118118

119+
public function testMissingMixedReturnInEmptyBody(): void
120+
{
121+
$this->checkExplicitMixedMissingReturn = true;
122+
$this->analyse([__DIR__ . '/data/missing-mixed-return-empty-body.php'], [
123+
[
124+
'Method MissingMixedReturnEmptyBody\HelloWorld::doFoo() should return mixed but return statement is missing.',
125+
11,
126+
],
127+
]);
128+
}
129+
119130
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace MissingMixedReturnEmptyBody;
4+
5+
class HelloWorld
6+
{
7+
8+
/**
9+
* @return mixed
10+
*/
11+
public function doFoo()
12+
{
13+
14+
}
15+
16+
}

0 commit comments

Comments
 (0)