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

Skip to content

Commit 66c99a0

Browse files
committed
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.
2 parents c94f186 + 2c9b283 commit 66c99a0

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function __construct($inputTimezone = null, $outputTimezone = null, $form
9090
* Transforms a DateTime object into a date string with the configured format
9191
* and timezone.
9292
*
93-
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object
93+
* @param \DateTime|\DateTimeInterface $value A DateTime object
9494
*
9595
* @return string A value as produced by PHP's date() function
9696
*
@@ -142,21 +142,21 @@ public function reverseTransform($value)
142142
throw new TransformationFailedException('Expected a string.');
143143
}
144144

145-
try {
146-
$outputTz = new \DateTimeZone($this->outputTimezone);
147-
$dateTime = \DateTime::createFromFormat($this->parseFormat, $value, $outputTz);
145+
$outputTz = new \DateTimeZone($this->outputTimezone);
146+
$dateTime = \DateTime::createFromFormat($this->parseFormat, $value, $outputTz);
148147

149-
$lastErrors = \DateTime::getLastErrors();
148+
$lastErrors = \DateTime::getLastErrors();
150149

151-
if (0 < $lastErrors['warning_count'] || 0 < $lastErrors['error_count']) {
152-
throw new TransformationFailedException(
153-
implode(', ', array_merge(
154-
array_values($lastErrors['warnings']),
155-
array_values($lastErrors['errors'])
156-
))
157-
);
158-
}
150+
if (0 < $lastErrors['warning_count'] || 0 < $lastErrors['error_count']) {
151+
throw new TransformationFailedException(
152+
implode(', ', array_merge(
153+
array_values($lastErrors['warnings']),
154+
array_values($lastErrors['errors'])
155+
))
156+
);
157+
}
159158

159+
try {
160160
// On PHP versions < 5.3.7 we need to emulate the pipe operator
161161
// and reset parts not given in the format to their equivalent
162162
// of the UNIX base timestamp.
@@ -224,8 +224,6 @@ public function reverseTransform($value)
224224
if ($this->inputTimezone !== $this->outputTimezone) {
225225
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
226226
}
227-
} catch (TransformationFailedException $e) {
228-
throw $e;
229227
} catch (\Exception $e) {
230228
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
231229
}

0 commit comments

Comments
 (0)