Skip to content

Commit

Permalink
Fix undefined variable in @var in unreachable code
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 8, 2021
1 parent 3d365fc commit ec4e7ed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Rules/PhpDoc/WrongVariableNameInVarTagRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr;
use PHPStan\Analyser\Scope;
use PHPStan\Node\UnreachableStatementNode;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\FileTypeMapper;
Expand Down Expand Up @@ -35,6 +36,7 @@ public function processNode(Node $node, Scope $scope): array
|| $node instanceof Node\Stmt\PropertyProperty
|| $node instanceof Node\Stmt\ClassConst
|| $node instanceof Node\Stmt\Const_
|| $node instanceof UnreachableStatementNode
) {
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,9 @@ public function testBug4504(): void
$this->analyse([__DIR__ . '/data/bug-4504.php'], []);
}

public function testBug4505(): void
{
$this->analyse([__DIR__ . '/data/bug-4505.php'], []);
}

}
17 changes: 17 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/data/bug-4505.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Bug4505;

class Foo
{

public function doFoo(): void {
if (true) {
return;
}

/** @var int $foobar */
$foobar = 1;
}

}

0 comments on commit ec4e7ed

Please sign in to comment.