Skip to content

Commit

Permalink
Marshal string values to null for FloatType and DecimalType.
Browse files Browse the repository at this point in the history
This makes then consistent with what IntegerType does.
  • Loading branch information
ADmad committed Aug 15, 2018
1 parent 432ed3b commit e960656
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
5 changes: 1 addition & 4 deletions src/Database/Type/DecimalType.php
Expand Up @@ -157,11 +157,8 @@ public function marshal($value)
if (is_numeric($value)) {
return (float)$value;
}
if (!is_scalar($value)) {
return null;
}

return $value;
return null;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions src/Database/Type/FloatType.php
Expand Up @@ -140,17 +140,14 @@ public function marshal($value)
if ($value === null || $value === '') {
return null;
}
if (is_numeric($value)) {
return (float)$value;
}
if (is_string($value) && $this->_useLocaleParser) {
return $this->_parseValue($value);
}
if (!is_scalar($value)) {
return null;
if (is_numeric($value)) {
return (float)$value;
}

return $value;
return null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Database/Type/DecimalTypeTest.php
Expand Up @@ -159,7 +159,7 @@ public function testToDatabaseInvalid()
public function testMarshal()
{
$result = $this->type->marshal('some data');
$this->assertSame('some data', $result);
$this->assertNull($result);

$result = $this->type->marshal('');
$this->assertNull($result);
Expand All @@ -168,7 +168,7 @@ public function testMarshal()
$this->assertSame(2.51, $result);

$result = $this->type->marshal('3.5 bears');
$this->assertSame('3.5 bears', $result);
$this->assertNull($result);

$result = $this->type->marshal(['3', '4']);
$this->assertNull($result);
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Database/Type/FloatTypeTest.php
Expand Up @@ -148,7 +148,7 @@ public function testToDatabase()
public function testMarshal()
{
$result = $this->type->marshal('some data');
$this->assertSame('some data', $result);
$this->assertNull($result);

$result = $this->type->marshal('');
$this->assertNull($result);
Expand All @@ -157,7 +157,7 @@ public function testMarshal()
$this->assertSame(2.51, $result);

$result = $this->type->marshal('3.5 bears');
$this->assertSame('3.5 bears', $result);
$this->assertNull($result);

$result = $this->type->marshal(['3', '4']);
$this->assertNull($result);
Expand Down

0 comments on commit e960656

Please sign in to comment.