Skip to content

Commit ec4e7ed

Browse files
committed
Fix undefined variable in @var in unreachable code
1 parent 3d365fc commit ec4e7ed

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/Rules/PhpDoc/WrongVariableNameInVarTagRule.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PhpParser\Node;
77
use PhpParser\Node\Expr;
88
use PHPStan\Analyser\Scope;
9+
use PHPStan\Node\UnreachableStatementNode;
910
use PHPStan\Rules\Rule;
1011
use PHPStan\Rules\RuleErrorBuilder;
1112
use PHPStan\Type\FileTypeMapper;
@@ -35,6 +36,7 @@ public function processNode(Node $node, Scope $scope): array
3536
|| $node instanceof Node\Stmt\PropertyProperty
3637
|| $node instanceof Node\Stmt\ClassConst
3738
|| $node instanceof Node\Stmt\Const_
39+
|| $node instanceof UnreachableStatementNode
3840
) {
3941
return [];
4042
}

tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,9 @@ public function testBug4504(): void
156156
$this->analyse([__DIR__ . '/data/bug-4504.php'], []);
157157
}
158158

159+
public function testBug4505(): void
160+
{
161+
$this->analyse([__DIR__ . '/data/bug-4505.php'], []);
162+
}
163+
159164
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Bug4505;
4+
5+
class Foo
6+
{
7+
8+
public function doFoo(): void {
9+
if (true) {
10+
return;
11+
}
12+
13+
/** @var int $foobar */
14+
$foobar = 1;
15+
}
16+
17+
}

0 commit comments

Comments
 (0)