Skip to content

Commit

Permalink
don't dump a scalar tag value on its own line
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Sep 10, 2019
1 parent 717182d commit 768f817
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
6 changes: 1 addition & 5 deletions Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,11 @@ public function dump($input, $inline = 0, $indent = 0, $flags = 0)
if ($value instanceof TaggedValue) {
$output .= sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag());

if ($inline - 1 <= 0) {
if ($inline - 1 <= 0 || null === $value->getValue() || is_scalar($value->getValue())) {
$output .= ' '.$this->dump($value->getValue(), $inline - 1, 0, $flags)."\n";
} else {
$output .= "\n";
$output .= $this->dump($value->getValue(), $inline - 1, $dumpAsMap ? $indent + $this->indentation : $indent + 2, $flags);

if (is_scalar($value->getValue())) {
$output .= "\n";
}
}

continue;
Expand Down
19 changes: 15 additions & 4 deletions Tests/DumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,21 @@ public function testDumpingNotInlinedScalarTaggedValue()
'user2' => new TaggedValue('user', 'john'),
];
$expected = <<<YAML
user1: !user
jane
user2: !user
john
user1: !user jane
user2: !user john
YAML;

$this->assertSame($expected, $this->dumper->dump($data, 2));
}

public function testDumpingNotInlinedNullTaggedValue()
{
$data = [
'foo' => new TaggedValue('bar', null),
];
$expected = <<<YAML
foo: !bar null
YAML;

Expand Down

0 comments on commit 768f817

Please sign in to comment.