Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f408a67

Browse filesBrowse files
minor #28403 Consistently throw exceptions on a single line (nicolas-grekas)
This PR was merged into the 2.8 branch. Discussion ---------- Consistently throw exceptions on a single line | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Just to be consistent. Prepared using php-cs-fixer + manual tweaks. Commits ------- 721dc86 Consistently throw exceptions on a single line
2 parents 40fff43 + 721dc86 commit f408a67
Copy full SHA for f408a67

File tree

Expand file treeCollapse file tree

67 files changed

+130
-594
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

67 files changed

+130
-594
lines changed

‎src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,7 @@ private function getSingleIdentifierValue($entity)
530530
private function getIdentifierValues($entity)
531531
{
532532
if (!$this->em->contains($entity)) {
533-
throw new RuntimeException(
534-
'Entities passed to the choice field must be managed. Maybe '.
535-
'persist them in the entity manager?'
536-
);
533+
throw new RuntimeException('Entities passed to the choice field must be managed. Maybe persist them in the entity manager?');
537534
}
538535

539536
$this->em->initializeObject($entity);

‎src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,7 @@ public function configureOptions(OptionsResolver $resolver)
237237
$em = $registry->getManagerForClass($options['class']);
238238

239239
if (null === $em) {
240-
throw new RuntimeException(sprintf(
241-
'Class "%s" seems not to be a managed Doctrine entity. '.
242-
'Did you forget to map it?',
243-
$options['class']
244-
));
240+
throw new RuntimeException(sprintf('Class "%s" seems not to be a managed Doctrine entity. Did you forget to map it?', $options['class']));
245241
}
246242

247243
return $em;

‎src/Symfony/Bundle/FrameworkBundle/Routing/Router.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
+1-8Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,7 @@ private function resolve($value)
152152
return (string) $resolved;
153153
}
154154

155-
throw new RuntimeException(sprintf(
156-
'The container parameter "%s", used in the route configuration value "%s", '.
157-
'must be a string or numeric, but it is of type %s.',
158-
$match[1],
159-
$value,
160-
\gettype($resolved)
161-
)
162-
);
155+
throw new RuntimeException(sprintf('The container parameter "%s", used in the route configuration value "%s", must be a string or numeric, but it is of type %s.', $match[1], $value, \gettype($resolved)));
163156
}, $value);
164157

165158
return str_replace('%%', '%', $escapedValue);

‎src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/GuardAuthenticationFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/GuardAuthenticationFactory.php
+2-8Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@ private function determineEntryPoint($defaultEntryPointId, array $config)
9494
if ($defaultEntryPointId) {
9595
// explode if they've configured the entry_point, but there is already one
9696
if ($config['entry_point']) {
97-
throw new \LogicException(sprintf(
98-
'The guard authentication provider cannot use the "%s" entry_point because another entry point is already configured by another provider! Either remove the other provider or move the entry_point configuration as a root key under your firewall (i.e. at the same level as "guard").',
99-
$config['entry_point']
100-
));
97+
throw new \LogicException(sprintf('The guard authentication provider cannot use the "%s" entry_point because another entry point is already configured by another provider! Either remove the other provider or move the entry_point configuration as a root key under your firewall (i.e. at the same level as "guard").', $config['entry_point']));
10198
}
10299

103100
return $defaultEntryPointId;
@@ -115,9 +112,6 @@ private function determineEntryPoint($defaultEntryPointId, array $config)
115112
}
116113

117114
// we have multiple entry points - we must ask them to configure one
118-
throw new \LogicException(sprintf(
119-
'Because you have multiple guard configurators, you need to set the "guard.entry_point" key to one of your configurators (%s)',
120-
implode(', ', $authenticatorIds)
121-
));
115+
throw new \LogicException(sprintf('Because you have multiple guard configurators, you need to set the "guard.entry_point" key to one of your configurators (%s)', implode(', ', $authenticatorIds)));
122116
}
123117
}

‎src/Symfony/Component/Config/Definition/ArrayNode.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Definition/ArrayNode.php
+5-18Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,13 @@ public function addChild(NodeInterface $node)
219219
protected function finalizeValue($value)
220220
{
221221
if (false === $value) {
222-
$msg = sprintf('Unsetting key for path "%s", value: %s', $this->getPath(), json_encode($value));
223-
throw new UnsetKeyException($msg);
222+
throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: %s', $this->getPath(), json_encode($value)));
224223
}
225224

226225
foreach ($this->children as $name => $child) {
227226
if (!array_key_exists($name, $value)) {
228227
if ($child->isRequired()) {
229-
$msg = sprintf('The child node "%s" at path "%s" must be configured.', $name, $this->getPath());
230-
$ex = new InvalidConfigurationException($msg);
228+
$ex = new InvalidConfigurationException(sprintf('The child node "%s" at path "%s" must be configured.', $name, $this->getPath()));
231229
$ex->setPath($this->getPath());
232230

233231
throw $ex;
@@ -260,11 +258,7 @@ protected function finalizeValue($value)
260258
protected function validateType($value)
261259
{
262260
if (!\is_array($value) && (!$this->allowFalse || false !== $value)) {
263-
$ex = new InvalidTypeException(sprintf(
264-
'Invalid type for path "%s". Expected array, but got %s',
265-
$this->getPath(),
266-
\gettype($value)
267-
));
261+
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected array, but got %s', $this->getPath(), \gettype($value)));
268262
if ($hint = $this->getInfo()) {
269263
$ex->addHint($hint);
270264
}
@@ -303,8 +297,7 @@ protected function normalizeValue($value)
303297

304298
// if extra fields are present, throw exception
305299
if (\count($value) && !$this->ignoreExtraKeys) {
306-
$msg = sprintf('Unrecognized option%s "%s" under "%s"', 1 === \count($value) ? '' : 's', implode(', ', array_keys($value)), $this->getPath());
307-
$ex = new InvalidConfigurationException($msg);
300+
$ex = new InvalidConfigurationException(sprintf('Unrecognized option%s "%s" under "%s"', 1 === \count($value) ? '' : 's', implode(', ', array_keys($value)), $this->getPath()));
308301
$ex->setPath($this->getPath());
309302

310303
throw $ex;
@@ -363,13 +356,7 @@ protected function mergeValues($leftSide, $rightSide)
363356
// no conflict
364357
if (!array_key_exists($k, $leftSide)) {
365358
if (!$this->allowNewKeys) {
366-
$ex = new InvalidConfigurationException(sprintf(
367-
'You are not allowed to define new elements for path "%s". '
368-
.'Please define all elements for this path in one config file. '
369-
.'If you are trying to overwrite an element, make sure you redefine it '
370-
.'with the same name.',
371-
$this->getPath()
372-
));
359+
$ex = new InvalidConfigurationException(sprintf('You are not allowed to define new elements for path "%s". Please define all elements for this path in one config file. If you are trying to overwrite an element, make sure you redefine it with the same name.', $this->getPath()));
373360
$ex->setPath($this->getPath());
374361

375362
throw $ex;

‎src/Symfony/Component/Config/Definition/BaseNode.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Definition/BaseNode.php
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,7 @@ public function getPath()
205205
final public function merge($leftSide, $rightSide)
206206
{
207207
if (!$this->allowOverwrite) {
208-
throw new ForbiddenOverwriteException(sprintf(
209-
'Configuration path "%s" cannot be overwritten. You have to '
210-
.'define all options for this path, and any of its sub-paths in '
211-
.'one configuration section.',
212-
$this->getPath()
213-
));
208+
throw new ForbiddenOverwriteException(sprintf('Configuration path "%s" cannot be overwritten. You have to define all options for this path, and any of its sub-paths in one configuration section.', $this->getPath()));
214209
}
215210

216211
$this->validateType($leftSide);

‎src/Symfony/Component/Config/Definition/BooleanNode.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Definition/BooleanNode.php
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ class BooleanNode extends ScalarNode
2626
protected function validateType($value)
2727
{
2828
if (!\is_bool($value)) {
29-
$ex = new InvalidTypeException(sprintf(
30-
'Invalid type for path "%s". Expected boolean, but got %s.',
31-
$this->getPath(),
32-
\gettype($value)
33-
));
29+
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected boolean, but got %s.', $this->getPath(), \gettype($value)));
3430
if ($hint = $this->getInfo()) {
3531
$ex->addHint($hint);
3632
}

‎src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php
+8-24Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -411,27 +411,19 @@ protected function validateConcreteNode(ArrayNode $node)
411411
$path = $node->getPath();
412412

413413
if (null !== $this->key) {
414-
throw new InvalidDefinitionException(
415-
sprintf('->useAttributeAsKey() is not applicable to concrete nodes at path "%s"', $path)
416-
);
414+
throw new InvalidDefinitionException(sprintf('->useAttributeAsKey() is not applicable to concrete nodes at path "%s"', $path));
417415
}
418416

419417
if (true === $this->atLeastOne) {
420-
throw new InvalidDefinitionException(
421-
sprintf('->requiresAtLeastOneElement() is not applicable to concrete nodes at path "%s"', $path)
422-
);
418+
throw new InvalidDefinitionException(sprintf('->requiresAtLeastOneElement() is not applicable to concrete nodes at path "%s"', $path));
423419
}
424420

425421
if ($this->default) {
426-
throw new InvalidDefinitionException(
427-
sprintf('->defaultValue() is not applicable to concrete nodes at path "%s"', $path)
428-
);
422+
throw new InvalidDefinitionException(sprintf('->defaultValue() is not applicable to concrete nodes at path "%s"', $path));
429423
}
430424

431425
if (false !== $this->addDefaultChildren) {
432-
throw new InvalidDefinitionException(
433-
sprintf('->addDefaultChildrenIfNoneSet() is not applicable to concrete nodes at path "%s"', $path)
434-
);
426+
throw new InvalidDefinitionException(sprintf('->addDefaultChildrenIfNoneSet() is not applicable to concrete nodes at path "%s"', $path));
435427
}
436428
}
437429

@@ -445,28 +437,20 @@ protected function validatePrototypeNode(PrototypedArrayNode $node)
445437
$path = $node->getPath();
446438

447439
if ($this->addDefaults) {
448-
throw new InvalidDefinitionException(
449-
sprintf('->addDefaultsIfNotSet() is not applicable to prototype nodes at path "%s"', $path)
450-
);
440+
throw new InvalidDefinitionException(sprintf('->addDefaultsIfNotSet() is not applicable to prototype nodes at path "%s"', $path));
451441
}
452442

453443
if (false !== $this->addDefaultChildren) {
454444
if ($this->default) {
455-
throw new InvalidDefinitionException(
456-
sprintf('A default value and default children might not be used together at path "%s"', $path)
457-
);
445+
throw new InvalidDefinitionException(sprintf('A default value and default children might not be used together at path "%s"', $path));
458446
}
459447

460448
if (null !== $this->key && (null === $this->addDefaultChildren || \is_int($this->addDefaultChildren) && $this->addDefaultChildren > 0)) {
461-
throw new InvalidDefinitionException(
462-
sprintf('->addDefaultChildrenIfNoneSet() should set default children names as ->useAttributeAsKey() is used at path "%s"', $path)
463-
);
449+
throw new InvalidDefinitionException(sprintf('->addDefaultChildrenIfNoneSet() should set default children names as ->useAttributeAsKey() is used at path "%s"', $path));
464450
}
465451

466452
if (null === $this->key && (\is_string($this->addDefaultChildren) || \is_array($this->addDefaultChildren))) {
467-
throw new InvalidDefinitionException(
468-
sprintf('->addDefaultChildrenIfNoneSet() might not set default children names as ->useAttributeAsKey() is not used at path "%s"', $path)
469-
);
453+
throw new InvalidDefinitionException(sprintf('->addDefaultChildrenIfNoneSet() might not set default children names as ->useAttributeAsKey() is not used at path "%s"', $path));
470454
}
471455
}
472456
}

‎src/Symfony/Component/Config/Definition/EnumNode.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Definition/EnumNode.php
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ protected function finalizeValue($value)
4343
$value = parent::finalizeValue($value);
4444

4545
if (!\in_array($value, $this->values, true)) {
46-
$ex = new InvalidConfigurationException(sprintf(
47-
'The value %s is not allowed for path "%s". Permissible values: %s',
48-
json_encode($value),
49-
$this->getPath(),
50-
implode(', ', array_map('json_encode', $this->values))));
46+
$ex = new InvalidConfigurationException(sprintf('The value %s is not allowed for path "%s". Permissible values: %s', json_encode($value), $this->getPath(), implode(', ', array_map('json_encode', $this->values))));
5147
$ex->setPath($this->getPath());
5248

5349
throw $ex;

‎src/Symfony/Component/Config/Definition/PrototypedArrayNode.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Definition/PrototypedArrayNode.php
+5-13Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ public function addChild(NodeInterface $node)
185185
protected function finalizeValue($value)
186186
{
187187
if (false === $value) {
188-
$msg = sprintf('Unsetting key for path "%s", value: %s', $this->getPath(), json_encode($value));
189-
throw new UnsetKeyException($msg);
188+
throw new UnsetKeyException(sprintf('Unsetting key for path "%s", value: %s', $this->getPath(), json_encode($value)));
190189
}
191190

192191
foreach ($value as $k => $v) {
@@ -199,8 +198,7 @@ protected function finalizeValue($value)
199198
}
200199

201200
if (\count($value) < $this->minNumberOfElements) {
202-
$msg = sprintf('The path "%s" should have at least %d element(s) defined.', $this->getPath(), $this->minNumberOfElements);
203-
$ex = new InvalidConfigurationException($msg);
201+
$ex = new InvalidConfigurationException(sprintf('The path "%s" should have at least %d element(s) defined.', $this->getPath(), $this->minNumberOfElements));
204202
$ex->setPath($this->getPath());
205203

206204
throw $ex;
@@ -232,8 +230,7 @@ protected function normalizeValue($value)
232230
foreach ($value as $k => $v) {
233231
if (null !== $this->keyAttribute && \is_array($v)) {
234232
if (!isset($v[$this->keyAttribute]) && \is_int($k) && !$isAssoc) {
235-
$msg = sprintf('The attribute "%s" must be set for path "%s".', $this->keyAttribute, $this->getPath());
236-
$ex = new InvalidConfigurationException($msg);
233+
$ex = new InvalidConfigurationException(sprintf('The attribute "%s" must be set for path "%s".', $this->keyAttribute, $this->getPath()));
237234
$ex->setPath($this->getPath());
238235

239236
throw $ex;
@@ -262,8 +259,7 @@ protected function normalizeValue($value)
262259
}
263260

264261
if (array_key_exists($k, $normalized)) {
265-
$msg = sprintf('Duplicate key "%s" for path "%s".', $k, $this->getPath());
266-
$ex = new DuplicateKeyException($msg);
262+
$ex = new DuplicateKeyException(sprintf('Duplicate key "%s" for path "%s".', $k, $this->getPath()));
267263
$ex->setPath($this->getPath());
268264

269265
throw $ex;
@@ -314,11 +310,7 @@ protected function mergeValues($leftSide, $rightSide)
314310
// no conflict
315311
if (!array_key_exists($k, $leftSide)) {
316312
if (!$this->allowNewKeys) {
317-
$ex = new InvalidConfigurationException(sprintf(
318-
'You are not allowed to define new elements for path "%s". '.
319-
'Please define all elements for this path in one config file.',
320-
$this->getPath()
321-
));
313+
$ex = new InvalidConfigurationException(sprintf('You are not allowed to define new elements for path "%s". Please define all elements for this path in one config file.', $this->getPath()));
322314
$ex->setPath($this->getPath());
323315

324316
throw $ex;

‎src/Symfony/Component/Config/Definition/ScalarNode.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Definition/ScalarNode.php
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ class ScalarNode extends VariableNode
3333
protected function validateType($value)
3434
{
3535
if (!is_scalar($value) && null !== $value) {
36-
$ex = new InvalidTypeException(sprintf(
37-
'Invalid type for path "%s". Expected scalar, but got %s.',
38-
$this->getPath(),
39-
\gettype($value)
40-
));
36+
$ex = new InvalidTypeException(sprintf('Invalid type for path "%s". Expected scalar, but got %s.', $this->getPath(), \gettype($value)));
4137
if ($hint = $this->getInfo()) {
4238
$ex->addHint($hint);
4339
}

‎src/Symfony/Component/Config/Definition/VariableNode.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Definition/VariableNode.php
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ protected function validateType($value)
8282
protected function finalizeValue($value)
8383
{
8484
if (!$this->allowEmptyValue && $this->isValueEmpty($value)) {
85-
$ex = new InvalidConfigurationException(sprintf(
86-
'The path "%s" cannot contain an empty value, but got %s.',
87-
$this->getPath(),
88-
json_encode($value)
89-
));
85+
$ex = new InvalidConfigurationException(sprintf('The path "%s" cannot contain an empty value, but got %s.', $this->getPath(), json_encode($value)));
9086
if ($hint = $this->getInfo()) {
9187
$ex->addHint($hint);
9288
}

‎src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php
+4-20Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@ public function setForeground($color = null)
9090
}
9191

9292
if (!isset(static::$availableForegroundColors[$color])) {
93-
throw new InvalidArgumentException(sprintf(
94-
'Invalid foreground color specified: "%s". Expected one of (%s)',
95-
$color,
96-
implode(', ', array_keys(static::$availableForegroundColors))
97-
));
93+
throw new InvalidArgumentException(sprintf('Invalid foreground color specified: "%s". Expected one of (%s)', $color, implode(', ', array_keys(static::$availableForegroundColors))));
9894
}
9995

10096
$this->foreground = static::$availableForegroundColors[$color];
@@ -116,11 +112,7 @@ public function setBackground($color = null)
116112
}
117113

118114
if (!isset(static::$availableBackgroundColors[$color])) {
119-
throw new InvalidArgumentException(sprintf(
120-
'Invalid background color specified: "%s". Expected one of (%s)',
121-
$color,
122-
implode(', ', array_keys(static::$availableBackgroundColors))
123-
));
115+
throw new InvalidArgumentException(sprintf('Invalid background color specified: "%s". Expected one of (%s)', $color, implode(', ', array_keys(static::$availableBackgroundColors))));
124116
}
125117

126118
$this->background = static::$availableBackgroundColors[$color];
@@ -136,11 +128,7 @@ public function setBackground($color = null)
136128
public function setOption($option)
137129
{
138130
if (!isset(static::$availableOptions[$option])) {
139-
throw new InvalidArgumentException(sprintf(
140-
'Invalid option specified: "%s". Expected one of (%s)',
141-
$option,
142-
implode(', ', array_keys(static::$availableOptions))
143-
));
131+
throw new InvalidArgumentException(sprintf('Invalid option specified: "%s". Expected one of (%s)', $option, implode(', ', array_keys(static::$availableOptions))));
144132
}
145133

146134
if (!\in_array(static::$availableOptions[$option], $this->options)) {
@@ -158,11 +146,7 @@ public function setOption($option)
158146
public function unsetOption($option)
159147
{
160148
if (!isset(static::$availableOptions[$option])) {
161-
throw new InvalidArgumentException(sprintf(
162-
'Invalid option specified: "%s". Expected one of (%s)',
163-
$option,
164-
implode(', ', array_keys(static::$availableOptions))
165-
));
149+
throw new InvalidArgumentException(sprintf('Invalid option specified: "%s". Expected one of (%s)', $option, implode(', ', array_keys(static::$availableOptions))));
166150
}
167151

168152
$pos = array_search(static::$availableOptions[$option], $this->options);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.