Skip to content

Commit 2de6a24

Browse files
committed
Fixed skipping shadowed trait method by a native method
1 parent 246afe8 commit 2de6a24

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
7979
use PHPStan\Reflection\ClassReflection;
8080
use PHPStan\Reflection\FunctionReflection;
81+
use PHPStan\Reflection\Native\NativeMethodReflection;
8182
use PHPStan\Reflection\ParametersAcceptor;
8283
use PHPStan\Reflection\ParametersAcceptorSelector;
8384
use PHPStan\Reflection\PassedByReference;
@@ -360,6 +361,9 @@ private function processStmtNode(
360361
&& $scope->getClassReflection()->hasNativeMethod($stmt->name->toString())
361362
) {
362363
$methodReflection = $scope->getClassReflection()->getNativeMethod($stmt->name->toString());
364+
if ($methodReflection instanceof NativeMethodReflection) {
365+
return new StatementResult($scope, false, false, []);
366+
}
363367
if ($methodReflection instanceof PhpMethodReflection) {
364368
$declaringTrait = $methodReflection->getDeclaringTrait();
365369
if ($declaringTrait === null || $declaringTrait->getName() !== $scope->getTraitReflection()->getName()) {

tests/PHPStan/Rules/Methods/AbstractMethodInNonAbstractClassRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ public function testbug3406AnotherCase(): void
5959
$this->analyse([__DIR__ . '/data/bug-3406_2.php'], []);
6060
}
6161

62+
public function testBug4214(): void
63+
{
64+
$this->analyse([__DIR__ . '/data/bug-4214.php'], []);
65+
}
66+
6267
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Bug4214;
4+
5+
trait AbstractTrait {
6+
abstract public function getMessage();
7+
}
8+
9+
class Test extends \Exception {
10+
use AbstractTrait;
11+
}

0 commit comments

Comments
 (0)