Skip to content

Commit e4e0855

Browse files
authored
Fix formatParameter() for floats (#1374)
1 parent 282661f commit e4e0855

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

lib/Doctrine/Migrations/InlineParameterFormatter.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use function implode;
1212
use function is_array;
1313
use function is_bool;
14+
use function is_float;
1415
use function is_int;
1516
use function is_string;
1617
use function sprintf;
@@ -52,7 +53,7 @@ public function formatParameters(array $params, array $types): string
5253
return sprintf('with parameters (%s)', implode(', ', $formattedParameters));
5354
}
5455

55-
private function formatParameter(mixed $value, string|int $type): string|int|null
56+
private function formatParameter(mixed $value, string|int $type): string|int|float|null
5657
{
5758
if (is_string($type) && Type::hasType($type)) {
5859
return Type::getType($type)->convertToDatabaseValue(
@@ -64,14 +65,14 @@ private function formatParameter(mixed $value, string|int $type): string|int|nul
6465
return $this->parameterToString($value);
6566
}
6667

67-
/** @param int[]|bool[]|string[]|array|int|string|bool $value */
68-
private function parameterToString(array|int|string|bool $value): string
68+
/** @param int[]|bool[]|string[]|float[]|array|int|string|float|bool $value */
69+
private function parameterToString(array|int|string|float|bool $value): string
6970
{
7071
if (is_array($value)) {
7172
return implode(', ', array_map($this->parameterToString(...), $value));
7273
}
7374

74-
if (is_int($value) || is_string($value)) {
75+
if (is_int($value) || is_string($value) || is_float($value)) {
7576
return (string) $value;
7677
}
7778

tests/Doctrine/Migrations/Tests/InlineParameterFormatterTest.php

+13-9
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,23 @@ public function testFormatParameters(): void
2323
$params = [
2424
0 => 'string value',
2525
1 => 1,
26-
2 => [1, true, false, 'string value'],
27-
3 => true,
28-
4 => false,
29-
5 => 'string value',
30-
6 => 1,
31-
7 => true,
32-
8 => false,
33-
9 => [1, true, false, 'string value'],
26+
2 => 1.5,
27+
3 => [1, true, false, 'string value'],
28+
4 => true,
29+
5 => false,
30+
6 => 'string value',
31+
7 => 1,
32+
8 => 1.5,
33+
9 => true,
34+
10 => false,
35+
11 => [1, true, false, 'string value'],
3436
'named' => 'string value',
3537
];
3638

3739
$types = [
3840
Types::STRING,
3941
Types::INTEGER,
42+
Types::FLOAT,
4043
Types::SIMPLE_ARRAY,
4144
Types::BOOLEAN,
4245
Types::BOOLEAN,
@@ -46,11 +49,12 @@ public function testFormatParameters(): void
4649
'unknown',
4750
'unknown',
4851
'unknown',
52+
'unknown',
4953
];
5054

5155
$result = $this->parameterFormatter->formatParameters($params, $types);
5256

53-
$expected = 'with parameters ([string value], [1], [1,1,,string value], [], [], [string value], [1], [true], [false], [1, true, false, string value], :named => [string value])';
57+
$expected = 'with parameters ([string value], [1], [1.5], [1,1,,string value], [], [], [string value], [1], [1.5], [true], [false], [1, true, false, string value], :named => [string value])';
5458

5559
self::assertSame($expected, $result);
5660
}

0 commit comments

Comments
 (0)