Skip to content

Commit f7899d9

Browse files
committed
ClassType::getTraits() returns TraitUse[] instead of string[] (BC break)
1 parent 1270e12 commit f7899d9

File tree

4 files changed

+6
-14
lines changed

4 files changed

+6
-14
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,8 @@ public function setTraits(array $traits): static
329329
}
330330

331331

332-
/** @return string[] */
332+
/** @return TraitUse[] */
333333
public function getTraits(): array
334-
{
335-
return array_keys($this->traits);
336-
}
337-
338-
339-
/** @internal */
340-
public function getTraitResolutions(): array
341334
{
342335
return $this->traits;
343336
}

src/PhpGenerator/Printer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function printClass(ClassType $class, ?PhpNamespace $namespace = null): s
135135
: fn($s) => $s;
136136

137137
$traits = [];
138-
foreach ($class->getTraitResolutions() as $trait) {
138+
foreach ($class->getTraits() as $trait) {
139139
$resolutions = $trait->getResolutions();
140140
$traits[] = Helpers::formatDocComment((string) $trait->getComment())
141141
. 'use ' . $resolver($trait->getName())

tests/PhpGenerator/ClassType.addMember.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $class = (new ClassType('Example'))
1919
Assert::same(['getHandle' => $method], $class->getMethods());
2020
Assert::same(['handle' => $property], $class->getProperties());
2121
Assert::same(['ROLE' => $const], $class->getConstants());
22-
Assert::same(['Foo\Bar'], $class->getTraits());
22+
Assert::same(['Foo\Bar' => $trait], $class->getTraits());
2323
Assert::same('', $method->getBody());
2424

2525

tests/PhpGenerator/ClassType.phpt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Assert::false($class->isInterface());
2424
Assert::false($class->isTrait());
2525
Assert::same([], $class->getExtends());
2626
Assert::same([], $class->getTraits());
27-
Assert::same([], $class->getTraitResolutions());
2827

2928
$class
3029
->setAbstract(true)
@@ -34,8 +33,8 @@ $class
3433
->addComment("Description of class.\nThis is example\n /**/")
3534
->addComment('@property-read Nette\Forms\Form $form');
3635

37-
$class->addTrait('ObjectTrait');
38-
$class->addTrait('AnotherTrait')
36+
$trait1 = $class->addTrait('ObjectTrait');
37+
$trait2 = $class->addTrait('AnotherTrait')
3938
->addResolution('sayHello as protected');
4039

4140
$class->addConstant('ROLE', 'admin');
@@ -45,7 +44,7 @@ $class->addConstant('ACTIVE', false)
4544
Assert::false($class->isFinal());
4645
Assert::true($class->isAbstract());
4746
Assert::same('ParentClass', $class->getExtends());
48-
Assert::same(['ObjectTrait', 'AnotherTrait'], $class->getTraits());
47+
Assert::same(['ObjectTrait' => $trait1, 'AnotherTrait' => $trait2], $class->getTraits());
4948
Assert::count(2, $class->getConstants());
5049
Assert::type(Nette\PhpGenerator\Constant::class, $class->getConstants()['ROLE']);
5150

0 commit comments

Comments
 (0)