Skip to content

Commit f6ca9c8

Browse files
committed
Do not require return type for renamed trait constructor
1 parent 2ebbb53 commit f6ca9c8

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/Rules/Methods/MissingMethodReturnTypehintRule.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ public function getNodeType(): string
3232
public function processNode(Node $node, Scope $scope): array
3333
{
3434
$methodReflection = $node->getMethodReflection();
35+
if ($scope->isInTrait()) {
36+
$methodNode = $node->getOriginalNode();
37+
$originalMethodName = $methodNode->getAttribute('originalTraitMethodName');
38+
if ($originalMethodName === '__construct') {
39+
return [];
40+
}
41+
}
3542
$returnType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
3643

3744
if ($returnType instanceof MixedType && !$returnType->isExplicitMixed()) {

tests/PHPStan/Rules/Methods/MissingMethodReturnTypehintRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,9 @@ public function testBug4758(): void
8888
$this->analyse([__DIR__ . '/data/bug-4758.php'], []);
8989
}
9090

91+
public function testBug9571(): void
92+
{
93+
$this->analyse([__DIR__ . '/data/bug-9571.php'], []);
94+
}
95+
9196
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Bug9571;
4+
5+
trait Foo {
6+
public function __construct() {}
7+
}
8+
9+
class HelloWorld
10+
{
11+
use Foo {
12+
__construct as baseConstructor;
13+
}
14+
15+
public function __construct()
16+
{
17+
$this->baseConstructor();
18+
}
19+
}

0 commit comments

Comments
 (0)