/** * Transforms a normalized format into a localized money string. * * @param int|float $value Normalized number * * @return string Localized money string. * * @throws TransformationFailedException If the given value is not numeric or * if the value can not be transformed. */ public function transform($value) { if (null !== $value) { if (!is_numeric($value)) { throw new TransformationFailedException('Expected a numeric.'); } $value /= $this->divisor; } return parent::transform($value); }
/** * Transforms a normalized format into a localized money string. * * @param number $value Normalized number * * @return string Localized money string. * * @throws UnexpectedTypeException if the given value is not numeric * @throws TransformationFailedException if the value can not be transformed */ public function transform($value) { if (null !== $value) { if (!is_numeric($value)) { throw new UnexpectedTypeException($value, 'numeric'); } $value /= $this->divisor; } return parent::transform($value); }
/** * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException */ public function testTransformExpectsNumeric() { $transformer = new NumberToLocalizedStringTransformer(); $transformer->transform('foo'); }