minor #16238 [Form] Remove unneeded catch and re-throw in DateTimeToStringTransformer (MisatoTremor)

This PR was submitted for the 2.8 branch but it was merged into the 2.3 branch instead (closes #16238).

Discussion
----------

[Form] Remove unneeded catch and re-throw in DateTimeToStringTransformer

| Q             | A
| ------------- | ---
| Fixed tickets | #16237
| License       | MIT

Also fixed PHPDoc param for ``transform``.

Commits
-------

2c9b283 [Form] Simplify DateTimeToStringTransformer Avoid unneeded catch and re-throw of the same exception.
This commit is contained in:
Fabien Potencier 2015-10-19 13:40:25 +02:00
commit 66c99a0b95
1 changed files with 15 additions and 17 deletions

View File

@ -90,7 +90,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
* Transforms a DateTime object into a date string with the configured format
* and timezone.
*
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object
* @param \DateTime|\DateTimeInterface $value A DateTime object
*
* @return string A value as produced by PHP's date() function
*
@ -142,7 +142,6 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
throw new TransformationFailedException('Expected a string.');
}
try {
$outputTz = new \DateTimeZone($this->outputTimezone);
$dateTime = \DateTime::createFromFormat($this->parseFormat, $value, $outputTz);
@ -157,6 +156,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
);
}
try {
// On PHP versions < 5.3.7 we need to emulate the pipe operator
// and reset parts not given in the format to their equivalent
// of the UNIX base timestamp.
@ -224,8 +224,6 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
if ($this->inputTimezone !== $this->outputTimezone) {
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
}
} catch (TransformationFailedException $e) {
throw $e;
} catch (\Exception $e) {
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
}