Skip to content

Commit d472aa0

Browse files
Merge branch '7.2' into 7.3
* 7.2: [DependencyInjection] Fix `ServiceLocatorTagPass` indexes handling Improve docblock on compile() [VarDumper] Fix dumping LazyObjectState when using VarExporter v8 Allow NumberToLocalizedStringTransformer empty values [Intl] Ensure data consistency between alpha and numeric codes [Intl] Add missing currency (NOK) localization (en_NO)
2 parents 9ee0a68 + 64dba21 commit d472aa0

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public function __construct(
3939
/**
4040
* Transforms a normalized format into a localized money string.
4141
*
42-
* @param int|float|null $value Normalized number
42+
* @param int|float|string|null $value Normalized number
4343
*
4444
* @throws TransformationFailedException if the given value is not numeric or
4545
* if the value cannot be transformed
4646
*/
4747
public function transform(mixed $value): string
4848
{
49-
if (null !== $value && 1 !== $this->divisor) {
49+
if (null !== $value && '' !== $value && 1 !== $this->divisor) {
5050
if (!is_numeric($value)) {
5151
throw new TransformationFailedException('Expected a numeric.');
5252
}

Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public function __construct(
4141
/**
4242
* Transforms a number type into localized number.
4343
*
44-
* @param int|float|null $value Number value
44+
* @param int|float|string|null $value Number value
4545
*
4646
* @throws TransformationFailedException if the given value is not numeric
4747
* or if the value cannot be transformed
4848
*/
4949
public function transform(mixed $value): string
5050
{
51-
if (null === $value) {
51+
if (null === $value || '' === $value) {
5252
return '';
5353
}
5454

Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ public function testTransformExpectsNumeric()
5454
$transformer->transform('abcd');
5555
}
5656

57+
public function testTransformEmptyString()
58+
{
59+
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
60+
61+
$this->assertSame('', $transformer->transform(''));
62+
}
63+
5764
public function testTransformEmpty()
5865
{
5966
$transformer = new MoneyToLocalizedStringTransformer();

Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public static function provideTransformations()
4949
{
5050
return [
5151
[null, '', 'de_AT'],
52+
['', '', 'de_AT'],
5253
[1, '1', 'de_AT'],
5354
[1.5, '1,5', 'de_AT'],
5455
[1234.5, '1234,5', 'de_AT'],

0 commit comments

Comments
 (0)