Skip to content

Commit

Permalink
fixed class resolving in trait usages [Closes #128]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 26, 2023
1 parent bf3b24b commit de1843f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/PhpGenerator/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private function addTraitToClass(ClassLike $class, Node\Stmt\TraitUse $node): vo
}

foreach ($node->adaptations as $item) {
$trait->addResolution(trim($this->toPhp($item), ';'));
$trait->addResolution(rtrim($this->getReformattedContents([$item], 0), ';'));
}

$this->addCommentAndAttributes($trait, $node);
Expand Down
5 changes: 3 additions & 2 deletions src/PhpGenerator/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ public function printClass(
$traits = [];
if ($class instanceof ClassType || $class instanceof TraitType || $class instanceof EnumType) {
foreach ($class->getTraits() as $trait) {
$resolutions = $trait->getResolutions();
$resolutions = implode(";\n", $trait->getResolutions());
$resolutions = Helpers::simplifyTaggedNames($resolutions, $this->namespace);
$traits[] = $this->printDocComment($trait)
. 'use ' . $resolver($trait->getName())
. ($resolutions
? " {\n" . $this->indentation . implode(";\n" . $this->indentation, $resolutions) . ";\n}\n"
? " {\n" . $this->indent($resolutions) . ";\n}\n"
: ";\n");
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/PhpGenerator/expected/Extractor.traits.expect
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class Class5
{
use Trait1;
use Trait1b {
\Trait1b::f1 insteadof \Trait1;
Trait1b::f1 insteadof Trait1;
// not yet supported
\Trait1b::f1 as private;
Trait1b::f1 as private;
}
}

0 comments on commit de1843f

Please sign in to comment.