Skip to content

Commit b79c08d

Browse files
committed
AbstractMethodInNonAbstractClassRule - fix abstract method from trait that overshadowed method from parent class
1 parent 3af7eaf commit b79c08d

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"nette/utils": "^3.1.1",
2222
"nikic/php-parser": "^4.5.0",
2323
"ondram/ci-detector": "^3.1",
24-
"ondrejmirtes/better-reflection": "^4.3.5",
24+
"ondrejmirtes/better-reflection": "^4.3.6",
2525
"phpdocumentor/type-resolver": "1.0.1",
2626
"phpstan/phpdoc-parser": "^0.4.7",
2727
"react/child-process": "^0.6.1",

tests/PHPStan/Rules/Methods/AbstractMethodInNonAbstractClassRuleTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PHPStan\Rules\Methods;
44

5+
use Bug3406\AbstractFoo;
6+
use Bug3406\ClassFoo;
57
use PHPStan\Rules\Rule;
68
use PHPStan\Testing\RuleTestCase;
79

@@ -38,4 +40,18 @@ public function testTraitProblem(): void
3840
$this->analyse([__DIR__ . '/data/trait-method-problem.php'], []);
3941
}
4042

43+
public function testBug3406(): void
44+
{
45+
$this->analyse([__DIR__ . '/data/bug-3406.php'], []);
46+
}
47+
48+
public function testBug3406ReflectionCheck(): void
49+
{
50+
$this->createBroker();
51+
$reflectionProvider = $this->createReflectionProvider();
52+
$reflection = $reflectionProvider->getClass(ClassFoo::class);
53+
$this->assertSame(AbstractFoo::class, $reflection->getNativeMethod('myFoo')->getDeclaringClass()->getName());
54+
$this->assertSame(ClassFoo::class, $reflection->getNativeMethod('myBar')->getDeclaringClass()->getName());
55+
}
56+
4157
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Bug3406;
4+
5+
abstract class AbstractFoo
6+
{
7+
8+
public function myFoo(): void
9+
{
10+
11+
}
12+
13+
public function myBar(): void
14+
{
15+
16+
}
17+
18+
}
19+
20+
trait TraitFoo
21+
{
22+
23+
abstract public function myFoo(): void;
24+
25+
public function myBar(): void
26+
{
27+
28+
}
29+
30+
}
31+
32+
final class ClassFoo extends AbstractFoo
33+
{
34+
35+
use TraitFoo;
36+
37+
}

0 commit comments

Comments
 (0)