Skip to content

Commit

Permalink
Fixed skipping shadowed trait method by a native method
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 12, 2021
1 parent 246afe8 commit 2de6a24
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\Native\NativeMethodReflection;
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Reflection\PassedByReference;
Expand Down Expand Up @@ -360,6 +361,9 @@ private function processStmtNode(
&& $scope->getClassReflection()->hasNativeMethod($stmt->name->toString())
) {
$methodReflection = $scope->getClassReflection()->getNativeMethod($stmt->name->toString());
if ($methodReflection instanceof NativeMethodReflection) {
return new StatementResult($scope, false, false, []);
}
if ($methodReflection instanceof PhpMethodReflection) {
$declaringTrait = $methodReflection->getDeclaringTrait();
if ($declaringTrait === null || $declaringTrait->getName() !== $scope->getTraitReflection()->getName()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ public function testbug3406AnotherCase(): void
$this->analyse([__DIR__ . '/data/bug-3406_2.php'], []);
}

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

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

namespace Bug4214;

trait AbstractTrait {
abstract public function getMessage();
}

class Test extends \Exception {
use AbstractTrait;
}

0 comments on commit 2de6a24

Please sign in to comment.