Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Rules/Methods/ParentMethodHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public function collectParentMethods(string $methodName, ClassReflection $class)
continue;
}

// Skip traits that inherited the method from a sub-trait
// The actual declaring trait will be processed separately
if ($methodReflection->getBetterReflection()->getDeclaringClass()->getName() !== $trait->getName()) {
continue;
}

$declaringTrait = $trait->getNativeMethod($methodName)->getDeclaringClass();
$parentMethods[] = [
$this->phpClassReflectionExtension->createUserlandMethodReflection(
Expand Down
7 changes: 7 additions & 0 deletions tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,4 +558,11 @@ public function testBug12073(): void
$this->analyse([__DIR__ . '/data/bug-12073.php'], []);
}

public function testBug14320(): void
{
$this->reportMaybes = true;
$this->reportStatic = true;
$this->analyse([__DIR__ . '/data/bug-14320.php'], []);
}

}
33 changes: 33 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-14320.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types = 1);

namespace Bug14320;

trait MyTrait
{
/**
* @param array<string, mixed> $data
* @return array<string, mixed>
*/
abstract protected function myFunction(array $data): array;
}

trait MyFirstTrait
{
use MyTrait;
}

abstract class MyAbstractClass
{
use MyFirstTrait;

/**
* @param array<string, mixed> $data
* @return array<string, mixed>
*/
protected function myFunction(array $data): array
{
return [
'hello' => 'bug',
];
}
}
Loading