Skip to content

Commit 00e4410

Browse files
committed
minor #14937 Standardize the name of the exception variables (javiereguiluz)
This PR was squashed before being merged into the 2.3 branch (closes #14937). Discussion ---------- Standardize the name of the exception variables | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - See symfony/symfony-docs#4491 for the context of this change. In Symfony source code there are 410 `try ... catch` blocks. More than 95% of them use `$e` as the name of the exception variable. After applying these changes, 407 out of 410 variables are named `$e`. These are the three cases where I didn't change the name of the `$e` variable: * Nested exception in https://github.com/symfony/symfony/blob/2.3/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php#L40. It uses `$e2` as the name of the nested variable. * Nested exception in https://github.com/symfony/symfony/blob/2.3/src/Symfony/Bundle/TwigBundle/TwigEngine.php#L82. I changed the name of the `$ex` variable to `$e2` to match the previous syntax. * https://github.com/symfony/symfony/blob/2.3/src/Symfony/Component/Console/Helper/DialogHelper.php#L463. I don't know if it's safe to change the name of the `$error` exception variable. Commits ------- e8b924c Standardize the name of the exception variables
2 parents 00c8d84 + 7923f6c commit 00e4410

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

Definition/ArrayNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ protected function finalizeValue($value)
256256

257257
try {
258258
$value[$name] = $child->finalize($value[$name]);
259-
} catch (UnsetKeyException $unset) {
259+
} catch (UnsetKeyException $e) {
260260
unset($value[$name]);
261261
}
262262
}

Definition/BaseNode.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,10 @@ final public function finalize($value)
302302
foreach ($this->finalValidationClosures as $closure) {
303303
try {
304304
$value = $closure($value);
305-
} catch (Exception $correctEx) {
306-
throw $correctEx;
307-
} catch (\Exception $invalid) {
308-
throw new InvalidConfigurationException(sprintf(
309-
'Invalid configuration for path "%s": %s',
310-
$this->getPath(),
311-
$invalid->getMessage()
312-
), $invalid->getCode(), $invalid);
305+
} catch (Exception $e) {
306+
throw $e;
307+
} catch (\Exception $e) {
308+
throw new InvalidConfigurationException(sprintf('Invalid configuration for path "%s": %s', $this->getPath(), $e->getMessage()), $e->getCode(), $e);
313309
}
314310
}
315311

Definition/PrototypedArrayNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ protected function finalizeValue($value)
211211
$this->prototype->setName($k);
212212
try {
213213
$value[$k] = $this->prototype->finalize($v);
214-
} catch (UnsetKeyException $unset) {
214+
} catch (UnsetKeyException $e) {
215215
unset($value[$k]);
216216
}
217217
}

0 commit comments

Comments
 (0)