Skip to content

Commit

Permalink
Printer: fixed falsy Attribute aren't printed (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
19bischof authored and dg committed Sep 29, 2023
1 parent c0b51b6 commit 7eb1b35
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/PhpGenerator/Printer.php
Expand Up @@ -424,7 +424,7 @@ protected function printAttributes(array $attrs, bool $inline = false): string
foreach ($attrs as $attr) {
$args = $this->dumper->format('...?:', $attr->getArguments());
$args = Helpers::simplifyTaggedNames($args, $this->namespace);
$items[] = $this->printType($attr->getName(), nullable: false) . ($args ? "($args)" : '');
$items[] = $this->printType($attr->getName(), nullable: false) . ($args === '' ? '' : "($args)");
$inline = $inline && !str_contains($args, "\n");
}

Expand Down
2 changes: 1 addition & 1 deletion tests/PhpGenerator/ClassType.attributes.phpt
Expand Up @@ -41,6 +41,6 @@ $method = $class->addMethod('getHandle')
$method->addParameter('mode')
->addComment('comment')
->addAttribute('ExampleAttribute')
->addAttribute('WithArguments', [123]);
->addAttribute('WithArguments', [0]);

sameFile(__DIR__ . '/expected/ClassType.attributes.expect', (string) $class);
2 changes: 1 addition & 1 deletion tests/PhpGenerator/expected/ClassType.attributes.expect
Expand Up @@ -22,7 +22,7 @@ class Example
#[ExampleAttribute]
public function getHandle(
/** comment */
#[ExampleAttribute, WithArguments(123)]
#[ExampleAttribute, WithArguments(0)]
$mode,
) {
}
Expand Down

0 comments on commit 7eb1b35

Please sign in to comment.