Skip to content

Commit e0eb850

Browse files
committed
TooWideMethodReturnTypehintRule - never report in a trait
1 parent c30e9a4 commit e0eb850

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Rules/TooWideTypehints/TooWideMethodReturnTypehintRule.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public function getNodeType(): string
3232

3333
public function processNode(Node $node, Scope $scope): array
3434
{
35+
if ($scope->isInTrait()) {
36+
return [];
37+
}
3538
$method = $node->getMethodReflection();
3639
$isFirstDeclaration = $method->getPrototype()->getDeclaringClass() === $method->getDeclaringClass();
3740
if (!$method->isPrivate()) {

tests/PHPStan/Rules/TooWideTypehints/data/tooWideMethodReturnType-private.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,20 @@ private function dolor6() {
9292
}
9393

9494
}
95+
96+
trait FooTrait
97+
{
98+
99+
private function doFoo(): ?int
100+
{
101+
return 1;
102+
}
103+
104+
}
105+
106+
class UsesFooTrait
107+
{
108+
109+
use FooTrait;
110+
111+
}

0 commit comments

Comments
 (0)