diff --git a/src/PhpGenerator/Extractor.php b/src/PhpGenerator/Extractor.php index f0f2abab..9daeeabd 100644 --- a/src/PhpGenerator/Extractor.php +++ b/src/PhpGenerator/Extractor.php @@ -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); diff --git a/src/PhpGenerator/Printer.php b/src/PhpGenerator/Printer.php index b3f380c8..1c5ee6bf 100644 --- a/src/PhpGenerator/Printer.php +++ b/src/PhpGenerator/Printer.php @@ -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"); } } diff --git a/tests/PhpGenerator/expected/Extractor.traits.expect b/tests/PhpGenerator/expected/Extractor.traits.expect index fa2e8c05..1f55b791 100644 --- a/tests/PhpGenerator/expected/Extractor.traits.expect +++ b/tests/PhpGenerator/expected/Extractor.traits.expect @@ -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; } }