Skip to content

Commit de1843f

Browse files
committed
fixed class resolving in trait usages [Closes #128]
1 parent bf3b24b commit de1843f

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/PhpGenerator/Extractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ private function addTraitToClass(ClassLike $class, Node\Stmt\TraitUse $node): vo
299299
}
300300

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

305305
$this->addCommentAndAttributes($trait, $node);

src/PhpGenerator/Printer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,12 @@ public function printClass(
147147
$traits = [];
148148
if ($class instanceof ClassType || $class instanceof TraitType || $class instanceof EnumType) {
149149
foreach ($class->getTraits() as $trait) {
150-
$resolutions = $trait->getResolutions();
150+
$resolutions = implode(";\n", $trait->getResolutions());
151+
$resolutions = Helpers::simplifyTaggedNames($resolutions, $this->namespace);
151152
$traits[] = $this->printDocComment($trait)
152153
. 'use ' . $resolver($trait->getName())
153154
. ($resolutions
154-
? " {\n" . $this->indentation . implode(";\n" . $this->indentation, $resolutions) . ";\n}\n"
155+
? " {\n" . $this->indent($resolutions) . ";\n}\n"
155156
: ";\n");
156157
}
157158
}

tests/PhpGenerator/expected/Extractor.traits.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ class Class5
101101
{
102102
use Trait1;
103103
use Trait1b {
104-
\Trait1b::f1 insteadof \Trait1;
104+
Trait1b::f1 insteadof Trait1;
105105
// not yet supported
106-
\Trait1b::f1 as private;
106+
Trait1b::f1 as private;
107107
}
108108
}

0 commit comments

Comments
 (0)