Skip to content

Commit 225c3ec

Browse files
19bischofdg
authored andcommitted
Printer: fixed falsy Attribute aren't printed (#142)
1 parent 8b728c6 commit 225c3ec

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/PhpGenerator/Printer.php

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

tests/PhpGenerator/ClassType.attributes.phpt

+1-1
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

+1-1
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)