8000 [Form] Clean unused code · symfony/symfony@d6ab282 · GitHub
[go: up one dir, main page]

Skip to content

Commit d6ab282

Browse files
committed
[Form] Clean unused code
1 parent 79f841c commit d6ab282

File tree

4 files changed

+36
-54
lines changed

4 files changed

+36
-54
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ protected function castParsedValue(int|float $value): int|float
183183
*/
184184
private function round(int|float $number): int|float
185185
{
186-
if (null !== $this->scale && null !== $this->roundingMode) {
186+
if (null !== $this->scale) {
187187
// shift number to maintain the correct scale during rounding
188188
$roundingCoef = 10 ** $this->scale;
189189
// string representation to avoid rounding errors, similar to bcmul()

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

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ protected function getNumberFormatter(): \NumberFormatter
180180

181181
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->scale);
182182

183-
if (null !== $this->roundingMode) {
184-
$formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $this->roundingMode);
185-
}
183+
$formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $this->roundingMode);
186184

187185
return $formatter;
188186
}
@@ -192,44 +190,40 @@ protected function getNumberFormatter(): \NumberFormatter
192190
*/
193191
private function round(int|float $number): int|float
194192
{
195-
if (null !== $this->scale && null !== $this->roundingMode) {
196-
// shift number to maintain the correct scale during rounding
197-
$roundingCoef = 10 ** $this->scale;
198-
199-
if (self::FRACTIONAL == $this->type) {
200-
$roundingCoef *= 100;
201-
}
202-
203-
// string representation to avoid rounding errors, similar to bcmul()
204-
$number = (string) ($number * $roundingCoef);
205-
206-
switch ($this->roundingMode) {
207-
case \NumberFormatter::ROUND_CEILING:
208-
$number = ceil($number);
209-
break;
210-
case \NumberFormatter::ROUND_FLOOR:
211-
$number = floor($number);
212-
break;
213-
case \NumberFormatter::ROUND_UP:
214-
$number = $number > 0 ? ceil($number) : floor($number);
215-
break;
216-
case \NumberFormatter::ROUND_DOWN:
217-
$number = $number > 0 ? floor($number) : ceil($number);
218-
break;
219-
case \NumberFormatter::ROUND_HALFEVEN:
220-
$number = round($number, 0, \PHP_ROUND_HALF_EVEN);
221-
break;
222-
case \NumberFormatter::ROUND_HALFUP:
223-
$number = round($number, 0, \PHP_ROUND_HALF_UP);
224-
break;
225-
case \NumberFormatter::ROUND_HALFDOWN:
226-
$number = round($number, 0, \PHP_ROUND_HALF_DOWN);
227-
break;
228-
}
229-
230-
$number = 1 === $roundingCoef ? (int) $number : $number / $roundingCoef;
231-
}
193+
// shift number to maintain the correct scale during rounding
194+
$roundingCoef = 10 ** $this->scale;
232195

233-
return $number;
196+
if (self::FRACTIONAL == $this->type) {
197+
$roundingCoef *= 100;
198+
}
199+
200+
// string representation to avoid rounding errors, similar to bcmul()
201+
$number = (string) ($number * $roundingCoef);
202+
203+
switch ($this->roundingMode) {
204+
case \NumberFormatter::ROUND_CEILING:
205+
$number = ceil($number);
206+
break;
207+
case \NumberFormatter::ROUND_FLOOR:
208+
$number = floor($number);
209+
break;
210+
case \NumberFormatter::ROUND_UP:
211+
$number = $number > 0 ? ceil($number) : floor($number);
212+
break;
213+
case \NumberFormatter::ROUND_DOWN:
214+
$number = $number > 0 ? floor($number) : ceil($number);
215+
break;
216+
case \NumberFormatter::ROUND_HALFEVEN:
217+
$number = round($number, 0, \PHP_ROUND_HALF_EVEN);
218+
break;
219+
case \NumberFormatter::ROUND_HALFUP:
220+
$number = round($number, 0, \PHP_ROUND_HALF_UP);
221+
break;
222+
case \NumberFormatter::ROUND_HALFDOWN:
223+
$number = round($number, 0, \PHP_ROUND_HALF_DOWN);
224+
break;
225+
}
226+
227+
$number = 1 === $roundingCoef ? (int) $number : $number / $roundingCoef;
234228
}
235229
}

src/Symfony/Component/Form/Form.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Symfony\Component\Form\Exception\OutOfBoundsException;
2222
use Symfony\Component\Form\Exception\RuntimeException;
2323
use Symfony\Component\Form\Exception\TransformationFailedException;
24-
use Symfony\Component\Form\Exception\UnexpectedTypeException;
2524
use Symfony\Component\Form\Extension\Core\Type\TextType;
2625
use Symfony\Component\Form\Util\FormUtil;
2726
use Symfony\Component\Form\Util\InheritDataAwareIterator;
@@ -727,12 +726,6 @@ public function add(FormInterface|string $child, string $type = null, array $opt
727726
}
728727

729728
if (!$child instanceof FormInterface) {
730-
if (!\is_string($child) && !\is_int($child)) {
731-
throw new UnexpectedTypeException($child, 'string or Symfony\Component\Form\FormInterface');
732-
}
733-
734-
$child = (string) $child;
735-
736729
// Never initialize child forms automatically
737730
$options['auto_initialize'] = false;
738731

src/Symfony/Component/Form/FormBuilder.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1515
use Symfony\Component\Form\Exception\BadMethodCallException;
1616
use Symfony\Component\Form\Exception\InvalidArgumentException;
17-
use Symfony\Component\Form\Exception\UnexpectedTypeException;
1817
use Symfony\Component\Form\Extension\Core\Type\TextType;
1918

2019
/**
@@ -60,10 +59,6 @@ public function add(FormBuilderInterface|string $child, string $type = null, arr
6059
return $this;
6160
}
6261

63-
if (!\is_string($child) && !\is_int($child)) {
64-
throw new UnexpectedTypeException($child, 'string or Symfony\Component\Form\FormBuilderInterface');
65-
}
66-
6762
// Add to "children" to maintain order
6863
$this->children[$child] = null;
6964
$this->unresolvedChildren[$child] = [$type, $options];

0 commit comments

Comments
 (0)
0