Browse Source

Make return data more consistent.

Return floats where possible, and remove unnecessary code from toPHP()
as the database will not return arrays from decimal columns.
Mark Story 9 years ago
parent
commit
025d298430

+ 2 - 5
src/Database/Type/DecimalType.php

@@ -63,7 +63,7 @@ class DecimalType extends Type implements TypeInterface
     /**
      * Convert integer data into the database format.
      *
-     * @param string|resource $value The value to convert.
+     * @param string|int|float $value The value to convert.
      * @param \Cake\Database\Driver $driver The driver instance to convert with.
      * @return string|null
      */
@@ -79,7 +79,7 @@ class DecimalType extends Type implements TypeInterface
             return $value;
         }
 
-        return sprintf('%F', (float)$value);
+        return sprintf('%F', $value);
     }
 
     /**
@@ -95,9 +95,6 @@ class DecimalType extends Type implements TypeInterface
         if ($value === null) {
             return null;
         }
-        if (is_array($value)) {
-            return 1;
-        }
 
         return (float)$value;
     }

+ 0 - 3
src/Database/Type/FloatType.php

@@ -72,9 +72,6 @@ class FloatType extends Type implements TypeInterface
         if ($value === null || $value === '') {
             return null;
         }
-        if (is_array($value)) {
-            return 1;
-        }
 
         return (float)$value;
     }

+ 1 - 1
tests/TestCase/Database/Type/DecimalTypeTest.php

@@ -73,7 +73,7 @@ class DecimalTypeTest extends TestCase
         $this->assertSame(2.0, $result);
 
         $result = $this->type->toPHP(['3', '4'], $this->driver);
-        $this->assertSame(1, $result);
+        $this->assertSame(1.0, $result);
     }
 
     /**

+ 1 - 1
tests/TestCase/Database/Type/FloatTypeTest.php

@@ -99,7 +99,7 @@ class FloatTypeTest extends TestCase
         $this->assertSame(2.51, $result);
 
         $result = $this->type->toDatabase(['3', '4'], $this->driver);
-        $this->assertSame(1, $result);
+        $this->assertSame(1.0, $result);
     }
 
     /**

+ 1 - 1
tests/TestCase/Database/TypeTest.php

@@ -210,7 +210,7 @@ class TypeTest extends TestCase
         $this->assertSame(3.14159, $type->toPHP('3.14159', $driver));
         $this->assertSame(3.14159, $type->toPHP(3.14159, $driver));
         $this->assertSame(3.0, $type->toPHP(3, $driver));
-        $this->assertSame(1, $type->toPHP(['3', '4'], $driver));
+        $this->assertSame(1.0, $type->toPHP(['3', '4'], $driver));
     }
 
     /**