Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Yaml] ensure dump indentation to be greather than zero #17979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ensure dump indentation to be greather than zero
  • Loading branch information
xabbuh committed Mar 1, 2016
commit fddc37e7409c170df7dd8c0815b4c040f90adacb
4 changes: 4 additions & 0 deletions 4 src/Symfony/Component/Yaml/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class Dumper
*/
public function __construct($indentation = 4)
{
if ($indentation < 1) {
throw new \InvalidArgumentException('The indentation must be greater than zero.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation can be a float number like 3.14? or should ensure that the indentation is a natural number?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docblock states that the argument must be an integer and we don't do scalar type checks in Symfony.

}

$this->indentation = $indentation;
}

Expand Down
18 changes: 18 additions & 0 deletions 18 src/Symfony/Component/Yaml/Tests/DumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,24 @@ public function testDumpMultiLineStringAsScalarBlock()

$this->assertSame(file_get_contents(__DIR__.'/Fixtures/multiple_lines_as_literal_block.yml'), $this->dumper->dump($data, 3, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The indentation must be greater than zero
*/
public function testZeroIndentationInConstructorThrowsException()
{
new Dumper(0);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The indentation must be greater than zero
*/
public function testNegativeIndentationInConstructorThrowsException()
{
new Dumper(-4);
}
}

class A
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.