Skip to content

Commit 14cb8f2

Browse files
ISSUE-15: Renamed BooleanToStringTransformer to BooleanToValueTransformer
1 parent 759c91f commit 14cb8f2

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/BooleanToStringTransformer.php renamed to src/BooleanToValueTransformer.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
use Symfony\Component\Form\Exception\TransformationFailedException;
2525

2626
/**
27-
* Transforms between a boolean and a string.
27+
* Transforms between a boolean and a scalar value.
2828
*
2929
* @author Raymond Schouten
3030
*
3131
* @since 2.3
3232
*/
33-
class BooleanToStringTransformer implements DataTransformerInterface
33+
class BooleanToValueTransformer implements DataTransformerInterface
3434
{
3535
/** @var string */
3636
private $trueValue;
@@ -41,10 +41,10 @@ class BooleanToStringTransformer implements DataTransformerInterface
4141
/**
4242
* Constructor.
4343
*
44-
* @param string $trueValue
45-
* @param string $falseValue
44+
* @param string|int|float|bool $trueValue
45+
* @param string|int|float|bool $falseValue
4646
*/
47-
public function __construct($trueValue = 'true', $falseValue = 'false')
47+
public function __construct($trueValue = true, $falseValue = false)
4848
{
4949
$this->trueValue = $trueValue;
5050
$this->falseValue = $falseValue;
@@ -55,7 +55,7 @@ public function __construct($trueValue = 'true', $falseValue = 'false')
5555
*
5656
* @param bool $value
5757
*
58-
* @return string
58+
* @return string|int|float|bool
5959
*
6060
* @throws \Symfony\Component\Form\Exception\TransformationFailedException
6161
*/
@@ -75,7 +75,7 @@ public function transform($value)
7575
/**
7676
* Transforms a value from the transformed representation to its original representation.
7777
*
78-
* @param string $value
78+
* @param string|int|float|bool $value
7979
*
8080
* @return bool
8181
*
@@ -91,12 +91,8 @@ public function reverseTransform($value)
9191
throw new TransformationFailedException('Expected a scalar.');
9292
}
9393

94-
$value = (string) $value;
95-
9694
if (!($value === $this->trueValue || $value === $this->falseValue)) {
97-
throw new TransformationFailedException(
98-
sprintf('Expected a string "%s" or "%s".', $this->trueValue, $this->falseValue)
99-
);
95+
throw new TransformationFailedException('Expected true/false boolean value.');
10096
}
10197

10298
return $value === $this->trueValue;

0 commit comments

Comments
 (0)