Skip to content

Commit

Permalink
[Serializer] Remove null check
Browse files Browse the repository at this point in the history
  • Loading branch information
battye committed Jun 14, 2019
1 parent 805dd49 commit 58a7f46
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
10 changes: 2 additions & 8 deletions src/Symfony/Component/Serializer/Encoder/CsvEncoder.php
Expand Up @@ -196,24 +196,18 @@ private function flatten(array $array, array &$result, $keySeparator, $parentKey

/**
* Ensures an actual value is used instead of a blank value when dealing
* with true, false and null (like a nullable bool in a database).
* with true and false.
*
* @param string $value
*
* @return string|int
* @return int
*/
private function cleanValueByType($value)
{
if (false === $value) {
return 0;
}

if (null === $value) {
// fputcsv will enclose a space
// https://github.com/php/php-src/blob/master/ext/standard/file.c
return ' ';
}

if (true === $value) {
return 1;
}
Expand Down
Expand Up @@ -29,20 +29,19 @@ protected function setUp()
$this->encoder = new CsvEncoder();
}

public function testTrueFalseNullValues()
public function testTrueFalseValues()
{
$data = [
'string' => 'foo',
'int' => 2,
'false' => false,
'true' => true,
'null' => null,
];

// Check that true, false and null are appropriately handled
// Check that true and false are appropriately handled
$this->assertEquals(<<<'CSV'
string,int,false,true,null
foo,2,0,1," "
string,int,false,true
foo,2,0,1
CSV
, $this->encoder->encode($data, 'csv'));
Expand Down

0 comments on commit 58a7f46

Please sign in to comment.