Skip to content

Commit 0bd48b4

Browse files
committed
FileTypeMapper - fix PHPDocs for renamed trait methods
1 parent 48c18ef commit 0bd48b4

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/Type/FileTypeMapper.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,21 @@ function (Node $node) use ($fileName, $lookForTrait, &$traitFound, $traitMethodA
398398
continue;
399399
}
400400

401-
if ($traitUseAdaptation->trait === null) {
401+
if ($traitUseAdaptation->newName === null) {
402402
continue;
403403
}
404404

405-
if ($traitUseAdaptation->newName === null) {
405+
$methodName = $traitUseAdaptation->method->toString();
406+
$newTraitName = $traitUseAdaptation->newName->toString();
407+
408+
if ($traitUseAdaptation->trait === null) {
409+
foreach ($node->traits as $traitName) {
410+
$traitMethodAliases[$traitName->toString()][$methodName] = $newTraitName;
411+
}
406412
continue;
407413
}
408414

409-
$traitMethodAliases[$traitUseAdaptation->trait->toString()][$traitUseAdaptation->method->toString()] = $traitUseAdaptation->newName->toString();
415+
$traitMethodAliases[$traitUseAdaptation->trait->toString()][$methodName] = $newTraitName;
410416
}
411417

412418
$useDocComment = null;

tests/PHPStan/Rules/Methods/MissingMethodReturnTypehintRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,9 @@ public function testBug9571(): void
9393
$this->analyse([__DIR__ . '/data/bug-9571.php'], []);
9494
}
9595

96+
public function testBug9571PhpDocs(): void
97+
{
98+
$this->analyse([__DIR__ . '/data/bug-9571-phpdocs.php'], []);
99+
}
100+
96101
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Bug9571PhpDocs;
4+
5+
trait DiContainerTrait
6+
{
7+
/**
8+
* @param array<string, mixed> $properties
9+
*
10+
* @return $this
11+
*/
12+
public function setDefaults(array $properties)
13+
{
14+
return $this;
15+
}
16+
}
17+
18+
class FactoryTestDefMock
19+
{
20+
use DiContainerTrait {
21+
setDefaults as _setDefaults;
22+
}
23+
}

0 commit comments

Comments
 (0)