Do not add space if empty string

This commit is contained in:
alexndlm 2021-08-31 11:08:22 +03:00 committed by GitHub
parent ea0b17460e
commit fac86158ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -271,7 +271,14 @@ class PhpDocNode implements Node
public function __toString(): string
{
return "/**\n * " . implode("\n * ", $this->children) . "\n */";
$children = array_map(
static function (PhpDocChildNode $child): string {
$s = (string) $child;
return $s === '' ? '' : ' ' . $s;
},
$this->children
);
return "/**\n *" . implode("\n *", $children) . "\n */";
}
}

View File

@ -25,6 +25,19 @@ final class NodePrintTest extends TestCase
]),
'/**
* It works
*/',
];
yield [
new PhpDocNode([
new PhpDocTextNode('It works'),
new PhpDocTextNode(''),
new PhpDocTextNode('with empty lines'),
]),
'/**
* It works
*
* with empty lines
*/',
];
}