Skip to content

Commit bd70b96

Browse files
authored
Merge branch refs/heads/1.12.x into 2.1.x
2 parents fd6f345 + 49c631a commit bd70b96

File tree

2 files changed

+61
-16
lines changed

2 files changed

+61
-16
lines changed

src/PhpDoc/PhpDocBlock.php

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,22 @@ public static function resolvePhpDocBlockForMethod(
195195
array $newPositionalParameterNames,
196196
): self
197197
{
198-
$parentReflections = self::getParentReflections($classReflection);
198+
$docBlocksFromParents = [];
199+
foreach (self::getParentReflections($classReflection) as $parentReflection) {
200+
$oneResult = self::resolveMethodPhpDocBlockFromClass(
201+
$parentReflection,
202+
$methodName,
203+
$explicit ?? $docComment !== null,
204+
$newPositionalParameterNames,
205+
);
206+
207+
if ($oneResult === null) { // Null if it is private or from a wrong trait.
208+
continue;
209+
}
210+
211+
$docBlocksFromParents[] = $oneResult;
212+
}
213+
199214
foreach ($classReflection->getTraits(true) as $traitReflection) {
200215
if (!$traitReflection->hasNativeMethod($methodName)) {
201216
continue;
@@ -210,23 +225,21 @@ public static function resolvePhpDocBlockForMethod(
210225
continue;
211226
}
212227

213-
$parentReflections[] = $traitReflection;
214-
}
215-
216-
$docBlocksFromParents = [];
217-
foreach ($parentReflections as $parentReflection) {
218-
$oneResult = self::resolveMethodPhpDocBlockFromClass(
219-
$parentReflection,
220-
$methodName,
221-
$explicit ?? $docComment !== null,
222-
$newPositionalParameterNames,
223-
);
224-
225-
if ($oneResult === null) { // Null if it is private or from a wrong trait.
226-
continue;
228+
$methodVariant = $traitMethod->getOnlyVariant();
229+
$positionalMethodParameterNames = [];
230+
foreach ($methodVariant->getParameters() as $methodParameter) {
231+
$positionalMethodParameterNames[] = $methodParameter->getName();
227232
}
228233

229-
$docBlocksFromParents[] = $oneResult;
234+
$docBlocksFromParents[] = new self(
235+
$traitMethod->getDocComment() ?? ResolvedPhpDocBlock::EMPTY_DOC_STRING,
236+
$classReflection->getFileName(),
237+
$classReflection,
238+
$traitReflection->getName(),
239+
$explicit ?? $traitMethod->getDocComment() !== null,
240+
self::remapParameterNames($newPositionalParameterNames, $positionalMethodParameterNames),
241+
[],
242+
);
230243
}
231244

232245
return new self(
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace AbstractGenericTraitMethodImplicitPhpDocInheritance;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @template T
9+
*/
10+
trait Foo
11+
{
12+
13+
/** @return T */
14+
abstract public function doFoo();
15+
}
16+
17+
class UseFoo
18+
{
19+
20+
/** @use Foo<int> */
21+
use Foo;
22+
23+
public function doFoo()
24+
{
25+
return 1;
26+
}
27+
28+
}
29+
30+
function (UseFoo $f): void {
31+
assertType('int', $f->doFoo());
32+
};

0 commit comments

Comments
 (0)