Skip to content

Commit

Permalink
FileTypeMapper - fix PHPDocs for renamed trait methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jul 5, 2023
1 parent 48c18ef commit 0bd48b4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Type/FileTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,21 @@ function (Node $node) use ($fileName, $lookForTrait, &$traitFound, $traitMethodA
continue;
}

if ($traitUseAdaptation->trait === null) {
if ($traitUseAdaptation->newName === null) {
continue;
}

if ($traitUseAdaptation->newName === null) {
$methodName = $traitUseAdaptation->method->toString();
$newTraitName = $traitUseAdaptation->newName->toString();

if ($traitUseAdaptation->trait === null) {
foreach ($node->traits as $traitName) {
$traitMethodAliases[$traitName->toString()][$methodName] = $newTraitName;
}
continue;
}

$traitMethodAliases[$traitUseAdaptation->trait->toString()][$traitUseAdaptation->method->toString()] = $traitUseAdaptation->newName->toString();
$traitMethodAliases[$traitUseAdaptation->trait->toString()][$methodName] = $newTraitName;
}

$useDocComment = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,9 @@ public function testBug9571(): void
$this->analyse([__DIR__ . '/data/bug-9571.php'], []);
}

public function testBug9571PhpDocs(): void
{
$this->analyse([__DIR__ . '/data/bug-9571-phpdocs.php'], []);
}

}
23 changes: 23 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-9571-phpdocs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Bug9571PhpDocs;

trait DiContainerTrait
{
/**
* @param array<string, mixed> $properties
*
* @return $this
*/
public function setDefaults(array $properties)
{
return $this;
}
}

class FactoryTestDefMock
{
use DiContainerTrait {
setDefaults as _setDefaults;
}
}

0 comments on commit 0bd48b4

Please sign in to comment.