Skip to content

Commit

Permalink
AbstractMethodInNonAbstractClassRule - fix abstract method from trait…
Browse files Browse the repository at this point in the history
… that overshadowed method from parent class
  • Loading branch information
ondrejmirtes committed Jun 8, 2020
1 parent 3af7eaf commit b79c08d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"nette/utils": "^3.1.1",
"nikic/php-parser": "^4.5.0",
"ondram/ci-detector": "^3.1",
"ondrejmirtes/better-reflection": "^4.3.5",
"ondrejmirtes/better-reflection": "^4.3.6",
"phpdocumentor/type-resolver": "1.0.1",
"phpstan/phpdoc-parser": "^0.4.7",
"react/child-process": "^0.6.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace PHPStan\Rules\Methods;

use Bug3406\AbstractFoo;
use Bug3406\ClassFoo;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;

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

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

public function testBug3406ReflectionCheck(): void
{
$this->createBroker();
$reflectionProvider = $this->createReflectionProvider();
$reflection = $reflectionProvider->getClass(ClassFoo::class);
$this->assertSame(AbstractFoo::class, $reflection->getNativeMethod('myFoo')->getDeclaringClass()->getName());
$this->assertSame(ClassFoo::class, $reflection->getNativeMethod('myBar')->getDeclaringClass()->getName());
}

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

namespace Bug3406;

abstract class AbstractFoo
{

public function myFoo(): void
{

}

public function myBar(): void
{

}

}

trait TraitFoo
{

abstract public function myFoo(): void;

public function myBar(): void
{

}

}

final class ClassFoo extends AbstractFoo
{

use TraitFoo;

}

0 comments on commit b79c08d

Please sign in to comment.