Skip to content

Commit 7eb1b35

Browse files
19bischofdg
authored andcommitted
Printer: fixed falsy Attribute aren't printed (#142)
1 parent c0b51b6 commit 7eb1b35

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/PhpGenerator/Printer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ protected function printAttributes(array $attrs, bool $inline = false): string
424424
foreach ($attrs as $attr) {
425425
$args = $this->dumper->format('...?:', $attr->getArguments());
426426
$args = Helpers::simplifyTaggedNames($args, $this->namespace);
427-
$items[] = $this->printType($attr->getName(), nullable: false) . ($args ? "($args)" : '');
427+
$items[] = $this->printType($attr->getName(), nullable: false) . ($args === '' ? '' : "($args)");
428428
$inline = $inline && !str_contains($args, "\n");
429429
}
430430

tests/PhpGenerator/ClassType.attributes.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ $method = $class->addMethod('getHandle')
4141
$method->addParameter('mode')
4242
->addComment('comment')
4343
->addAttribute('ExampleAttribute')
44-
->addAttribute('WithArguments', [123]);
44+
->addAttribute('WithArguments', [0]);
4545

4646
sameFile(__DIR__ . '/expected/ClassType.attributes.expect', (string) $class);

tests/PhpGenerator/expected/ClassType.attributes.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Example
2222
#[ExampleAttribute]
2323
public function getHandle(
2424
/** comment */
25-
#[ExampleAttribute, WithArguments(123)]
25+
#[ExampleAttribute, WithArguments(0)]
2626
$mode,
2727
) {
2828
}

0 commit comments

Comments
 (0)