Skip to content

Commit

Permalink
Merge branch refs/heads/1.12.x into 2.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
phpstan-bot authored Feb 5, 2025
2 parents fd6f345 + 49c631a commit bd70b96
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 16 deletions.
45 changes: 29 additions & 16 deletions src/PhpDoc/PhpDocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,22 @@ public static function resolvePhpDocBlockForMethod(
array $newPositionalParameterNames,
): self
{
$parentReflections = self::getParentReflections($classReflection);
$docBlocksFromParents = [];
foreach (self::getParentReflections($classReflection) as $parentReflection) {
$oneResult = self::resolveMethodPhpDocBlockFromClass(
$parentReflection,
$methodName,
$explicit ?? $docComment !== null,
$newPositionalParameterNames,
);

if ($oneResult === null) { // Null if it is private or from a wrong trait.
continue;
}

$docBlocksFromParents[] = $oneResult;
}

foreach ($classReflection->getTraits(true) as $traitReflection) {
if (!$traitReflection->hasNativeMethod($methodName)) {
continue;
Expand All @@ -210,23 +225,21 @@ public static function resolvePhpDocBlockForMethod(
continue;
}

$parentReflections[] = $traitReflection;
}

$docBlocksFromParents = [];
foreach ($parentReflections as $parentReflection) {
$oneResult = self::resolveMethodPhpDocBlockFromClass(
$parentReflection,
$methodName,
$explicit ?? $docComment !== null,
$newPositionalParameterNames,
);

if ($oneResult === null) { // Null if it is private or from a wrong trait.
continue;
$methodVariant = $traitMethod->getOnlyVariant();
$positionalMethodParameterNames = [];
foreach ($methodVariant->getParameters() as $methodParameter) {
$positionalMethodParameterNames[] = $methodParameter->getName();
}

$docBlocksFromParents[] = $oneResult;
$docBlocksFromParents[] = new self(
$traitMethod->getDocComment() ?? ResolvedPhpDocBlock::EMPTY_DOC_STRING,
$classReflection->getFileName(),
$classReflection,
$traitReflection->getName(),
$explicit ?? $traitMethod->getDocComment() !== null,
self::remapParameterNames($newPositionalParameterNames, $positionalMethodParameterNames),
[],
);
}

return new self(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace AbstractGenericTraitMethodImplicitPhpDocInheritance;

use function PHPStan\Testing\assertType;

/**
* @template T
*/
trait Foo
{

/** @return T */
abstract public function doFoo();
}

class UseFoo
{

/** @use Foo<int> */
use Foo;

public function doFoo()
{
return 1;
}

}

function (UseFoo $f): void {
assertType('int', $f->doFoo());
};

0 comments on commit bd70b96

Please sign in to comment.