Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 31f8cb9

Browse files
committed
feature #28569 [Form] deprecate precision in IntegerToLocalizedStringTransformer (xabbuh)
This PR was merged into the 4.2-dev branch. Discussion ---------- [Form] deprecate precision in IntegerToLocalizedStringTransformer | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #8631 | License | MIT | Doc PR | Commits ------- 65362e0 deprecate precision in IntegerToLocalizedStringTransformer
2 parents 792ec82 + 65362e0 commit 31f8cb9

File tree

6 files changed

+59
-8
lines changed

6 files changed

+59
-8
lines changed

UPGRADE-4.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Form
5656
----
5757

5858
* The `scale` option of the `IntegerType` is deprecated.
59+
* The `$scale` argument of the `IntegerToLocalizedStringTransformer` is deprecated.
5960

6061
* Deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered.
6162
Instead of expecting such calls to return empty strings, check if the field has already been rendered.

UPGRADE-5.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ EventDispatcher
6464

6565
* The `TraceableEventDispatcherInterface` has been removed.
6666

67+
Form
68+
----
69+
70+
* The `$scale` argument of the `IntegerToLocalizedStringTransformer` was removed.
71+
6772
Finder
6873
------
6974

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
4.2.0
55
-----
66

7+
* deprecated the `$scale` argument of the `IntegerToLocalizedStringTransformer`
78
* added `Symfony\Component\Form\ClearableErrorsInterface`
89
* deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered
910
* deprecated the `scale` option of the `IntegerType`

src/Symfony/Component/Form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransfo
2222
/**
2323
* Constructs a transformer.
2424
*
25-
* @param int $scale Unused
2625
* @param bool $grouping Whether thousands should be grouped
2726
* @param int $roundingMode One of the ROUND_ constants in this class
2827
*/
29-
public function __construct(?int $scale = 0, ?bool $grouping = false, int $roundingMode = self::ROUND_DOWN)
28+
public function __construct($grouping = false, $roundingMode = self::ROUND_DOWN)
3029
{
30+
if (\is_int($grouping) || \is_bool($roundingMode) || 2 < \func_num_args()) {
31+
@trigger_error(sprintf('Passing a precision as the first value to %s::__construct() is deprecated since Symfony 4.2 and support for it will be dropped in 5.0.', __CLASS__), E_USER_DEPRECATED);
32+
33+
$grouping = $roundingMode;
34+
$roundingMode = 2 < \func_num_args() ? func_get_arg(2) : self::ROUND_DOWN;
35+
}
36+
3137
parent::__construct(0, $grouping, $roundingMode);
3238
}
3339

src/Symfony/Component/Form/Extension/Core/Type/IntegerType.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ class IntegerType extends AbstractType
2323
*/
2424
public function buildForm(FormBuilderInterface $builder, array $options)
2525
{
26-
$builder->addViewTransformer(
27-
new IntegerToLocalizedStringTransformer(
28-
null,
29-
$options['grouping'],
30-
$options['rounding_mode']
31-
));
26+
$builder->addViewTransformer(new IntegerToLocalizedStringTransformer($options['grouping'], $options['rounding_mode']));
3227
}
3328

3429
/**

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformerTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ public function transformWithRoundingProvider()
7979
* @dataProvider transformWithRoundingProvider
8080
*/
8181
public function testTransformWithRounding($input, $output, $roundingMode)
82+
{
83+
$transformer = new IntegerToLocalizedStringTransformer(null, $roundingMode);
84+
85+
$this->assertEquals($output, $transformer->transform($input));
86+
}
87+
88+
/**
89+
* @group legacy
90+
* @expectedDeprecation Passing a precision as the first value to %s::__construct() is deprecated since Symfony 4.2 and support for it will be dropped in 5.0.
91+
* @dataProvider transformWithRoundingProvider
92+
*/
93+
public function testTransformWithRoundingUsingLegacyConstructorSignature($input, $output, $roundingMode)
8294
{
8395
$transformer = new IntegerToLocalizedStringTransformer(null, null, $roundingMode);
8496

@@ -114,6 +126,25 @@ public function testReverseTransformWithGrouping()
114126

115127
\Locale::setDefault('de_DE');
116128

129+
$transformer = new IntegerToLocalizedStringTransformer(true);
130+
131+
$this->assertEquals(1234, $transformer->reverseTransform('1.234,5'));
132+
$this->assertEquals(12345, $transformer->reverseTransform('12.345,912'));
133+
$this->assertEquals(1234, $transformer->reverseTransform('1234,5'));
134+
$this->assertEquals(12345, $transformer->reverseTransform('12345,912'));
135+
}
136+
137+
/**
138+
* @group legacy
139+
* @expectedDeprecation Passing a precision as the first value to %s::__construct() is deprecated since Symfony 4.2 and support for it will be dropped in 5.0.
140+
*/
141+
public function testReverseTransformWithGroupingUsingLegacyConstructorSignature()
142+
{
143+
// Since we test against "de_DE", we need the full implementation
144+
IntlTestHelper::requireFullIntl($this, false);
145+
146+
\Locale::setDefault('de_DE');
147+
117148
$transformer = new IntegerToLocalizedStringTransformer(null, true);
118149

119150
$this->assertEquals(1234, $transformer->reverseTransform('1.234,5'));
@@ -177,6 +208,18 @@ public function reverseTransformWithRoundingProvider()
177208
* @dataProvider reverseTransformWithRoundingProvider
178209
*/
179210
public function testReverseTransformWithRounding($input, $output, $roundingMode)
211+
{
212+
$transformer = new IntegerToLocalizedStringTransformer(null, $roundingMode);
213+
214+
$this->assertEquals($output, $transformer->reverseTransform($input));
215+
}
216+
217+
/**
218+
* @group legacy
219+
* @expectedDeprecation Passing a precision as the first value to %s::__construct() is deprecated since Symfony 4.2 and support for it will be dropped in 5.0.
220+
* @dataProvider reverseTransformWithRoundingProvider
221+
*/
222+
public function testReverseTransformWithRoundingUsingLegacyConstructorSignature($input, $output, $roundingMode)
180223
{
181224
$transformer = new IntegerToLocalizedStringTransformer(null, null, $roundingMode);
182225

0 commit comments

Comments
 (0)