Skip to content

Commit 82436ba

Browse files
Consistently throw exceptions on a single line
1 parent 557846f commit 82436ba

15 files changed

+23
-113
lines changed

ChoiceList/ArrayKeyChoiceList.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ class ArrayKeyChoiceList extends ArrayChoiceList
7070
public static function toArrayKey($choice)
7171
{
7272
if (!is_scalar($choice) && null !== $choice) {
73-
throw new InvalidArgumentException(sprintf(
74-
'The value of type "%s" cannot be converted to a valid array key.',
75-
\gettype($choice)
76-
));
73+
throw new InvalidArgumentException(sprintf('The value of type "%s" cannot be converted to a valid array key.', \gettype($choice)));
7774
}
7875

7976
if (\is_bool($choice) || (string) (int) $choice === (string) $choice) {

Extension/Core/DataTransformer/ArrayToPartsTransformer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ public function reverseTransform($array)
7676
return;
7777
}
7878

79-
throw new TransformationFailedException(
80-
sprintf('The keys "%s" should not be empty', implode('", "', $emptyKeys)
81-
));
79+
throw new TransformationFailedException(sprintf('The keys "%s" should not be empty', implode('", "', $emptyKeys)));
8280
}
8381

8482
return $result;

Extension/Core/DataTransformer/DateTimeToArrayTransformer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ public function reverseTransform($value)
135135
}
136136

137137
if (\count($emptyFields) > 0) {
138-
throw new TransformationFailedException(
139-
sprintf('The fields "%s" should not be empty', implode('", "', $emptyFields)
140-
));
138+
throw new TransformationFailedException(sprintf('The fields "%s" should not be empty', implode('", "', $emptyFields)));
141139
}
142140

143141
if (isset($value['month']) && !ctype_digit((string) $value['month'])) {

Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,7 @@ public function reverseTransform($rfc3339)
8181

8282
if (preg_match('/(\d{4})-(\d{2})-(\d{2})/', $rfc3339, $matches)) {
8383
if (!checkdate($matches[2], $matches[3], $matches[1])) {
84-
throw new TransformationFailedException(sprintf(
85-
'The date "%s-%s-%s" is not a valid date.',
86-
$matches[1],
87-
$matches[2],
88-
$matches[3]
89-
));
84+
throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
9085
}
9186
}
9287

Extension/Core/DataTransformer/DateTimeToStringTransformer.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,7 @@ public function reverseTransform($value)
126126
$lastErrors = \DateTime::getLastErrors();
127127

128128
if (0 < $lastErrors['warning_count'] || 0 < $lastErrors['error_count']) {
129-
throw new TransformationFailedException(
130-
implode(', ', array_merge(
131-
array_values($lastErrors['warnings']),
132-
array_values($lastErrors['errors'])
133-
))
134-
);
129+
throw new TransformationFailedException(implode(', ', array_merge(array_values($lastErrors['warnings']), array_values($lastErrors['errors']))));
135130
}
136131

137132
try {

Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,7 @@ public function reverseTransform($value)
225225
$remainder = trim($remainder, " \t\n\r\0\x0b\xc2\xa0");
226226

227227
if ('' !== $remainder) {
228-
throw new TransformationFailedException(
229-
sprintf('The number contains unrecognized characters: "%s"', $remainder)
230-
);
228+
throw new TransformationFailedException(sprintf('The number contains unrecognized characters: "%s"', $remainder));
231229
}
232230
}
233231

Extension/Core/DataTransformer/ValueToDuplicatesTransformer.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ public function reverseTransform($array)
6464
foreach ($this->keys as $key) {
6565
if (isset($array[$key]) && '' !== $array[$key] && false !== $array[$key] && array() !== $array[$key]) {
6666
if ($array[$key] !== $result) {
67-
throw new TransformationFailedException(
68-
'All values in the array should be the same'
69-
);
67+
throw new TransformationFailedException('All values in the array should be the same');
7068
}
7169
} else {
7270
$emptyKeys[] = $key;
@@ -79,9 +77,7 @@ public function reverseTransform($array)
7977
return;
8078
}
8179

82-
throw new TransformationFailedException(
83-
sprintf('The keys "%s" should not be empty', implode('", "', $emptyKeys)
84-
));
80+
throw new TransformationFailedException(sprintf('The keys "%s" should not be empty', implode('", "', $emptyKeys)));
8581
}
8682

8783
return $result;

Extension/Core/EventListener/FixCheckboxInputListener.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ public function preSubmit(FormEvent $event)
6666
}
6767

6868
if (\count($submittedValues) > 0) {
69-
throw new TransformationFailedException(sprintf(
70-
'The following choices were not found: "%s"',
71-
implode('", "', array_keys($submittedValues))
72-
));
69+
throw new TransformationFailedException(sprintf('The following choices were not found: "%s"', implode('", "', array_keys($submittedValues))));
7370
}
7471
} elseif ('' === $data || null === $data) {
7572
// Empty values are always accepted.

Extension/Core/Type/ChoiceType.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
132132

133133
// Throw exception if unknown values were submitted
134134
if (\count($unknownValues) > 0) {
135-
throw new TransformationFailedException(sprintf(
136-
'The choices "%s" do not exist in the choice list.',
137-
implode('", "', array_keys($unknownValues))
138-
));
135+
throw new TransformationFailedException(sprintf('The choices "%s" do not exist in the choice list.', implode('", "', array_keys($unknownValues))));
139136
}
140137

141138
$event->setData($data);

Extension/DependencyInjection/DependencyInjectionExtension.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@ public function getType($name)
4343

4444
// BC: validate result of getName() for legacy names (non-FQCN)
4545
if ($name !== \get_class($type) && $type->getName() !== $name) {
46-
throw new InvalidArgumentException(
47-
sprintf('The type name specified for the service "%s" does not match the actual name. Expected "%s", given "%s"',
48-
$this->typeServiceIds[$name],
49-
$name,
50-
$type->getName()
51-
)
52-
);
46+
throw new InvalidArgumentException(sprintf('The type name specified for the service "%s" does not match the actual name. Expected "%s", given "%s"', $this->typeServiceIds[$name], $name, $type->getName()));
5347
}
5448

5549
return $type;
@@ -70,13 +64,7 @@ public function getTypeExtensions($name)
7064

7165
// validate result of getExtendedType() to ensure it is consistent with the service definition
7266
if ($extension->getExtendedType() !== $name) {
73-
throw new InvalidArgumentException(
74-
sprintf('The extended type specified for the service "%s" does not match the actual extended type. Expected "%s", given "%s".',
75-
$serviceId,
76-
$name,
77-
$extension->getExtendedType()
78-
)
79-
);
67+
throw new InvalidArgumentException(sprintf('The extended type specified for the service "%s" does not match the actual extended type. Expected "%s", given "%s".', $serviceId, $name, $extension->getExtendedType()));
8068
}
8169
}
8270
}

Form.php

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,7 @@ public function setData($modelData)
359359
? 'an instance of class '.\get_class($viewData)
360360
: 'a(n) '.\gettype($viewData);
361361

362-
throw new LogicException(
363-
'The form\'s view data is expected to be an instance of class '.
364-
$dataClass.', but is '.$actualType.'. You can avoid this error '.
365-
'by setting the "data_class" option to null or by adding a view '.
366-
'transformer that transforms '.$actualType.' to an instance of '.
367-
$dataClass.'.'
368-
);
362+
throw new LogicException('The form\'s view data is expected to be an instance of class '.$dataClass.', but is '.$actualType.'. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms '.$actualType.' to an instance of '.$dataClass.'.');
369363
}
370364
}
371365

@@ -915,11 +909,7 @@ public function add($child, $type = null, array $options = array())
915909
$child = $this->config->getFormFactory()->createNamed($child, $type, null, $options);
916910
}
917911
} elseif ($child->getConfig()->getAutoInitialize()) {
918-
throw new RuntimeException(sprintf(
919-
'Automatic initialization is only supported on root forms. You '.
920-
'should set the "auto_initialize" option to false on the field "%s".',
921-
$child->getName()
922-
));
912+
throw new RuntimeException(sprintf('Automatic initialization is only supported on root forms. You should set the "auto_initialize" option to false on the field "%s".', $child->getName()));
923913
}
924914

925915
$this->children[$child->getName()] = $child;
@@ -1093,11 +1083,7 @@ private function modelToNorm($value)
10931083
$value = $transformer->transform($value);
10941084
}
10951085
} catch (TransformationFailedException $exception) {
1096-
throw new TransformationFailedException(
1097-
'Unable to transform value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(),
1098-
$exception->getCode(),
1099-
$exception
1100-
);
1086+
throw new TransformationFailedException('Unable to transform value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(), $exception->getCode(), $exception);
11011087
}
11021088

11031089
return $value;
@@ -1121,11 +1107,7 @@ private function normToModel($value)
11211107
$value = $transformers[$i]->reverseTransform($value);
11221108
}
11231109
} catch (TransformationFailedException $exception) {
1124-
throw new TransformationFailedException(
1125-
'Unable to reverse value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(),
1126-
$exception->getCode(),
1127-
$exception
1128-
);
1110+
throw new TransformationFailedException('Unable to reverse value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(), $exception->getCode(), $exception);
11291111
}
11301112

11311113
return $value;
@@ -1156,11 +1138,7 @@ private function normToView($value)
11561138
$value = $transformer->transform($value);
11571139
}
11581140
} catch (TransformationFailedException $exception) {
1159-
throw new TransformationFailedException(
1160-
'Unable to transform value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(),
1161-
$exception->getCode(),
1162-
$exception
1163-
);
1141+
throw new TransformationFailedException('Unable to transform value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(), $exception->getCode(), $exception);
11641142
}
11651143

11661144
return $value;
@@ -1188,11 +1166,7 @@ private function viewToNorm($value)
11881166
$value = $transformers[$i]->reverseTransform($value);
11891167
}
11901168
} catch (TransformationFailedException $exception) {
1191-
throw new TransformationFailedException(
1192-
'Unable to reverse value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(),
1193-
$exception->getCode(),
1194-
$exception
1195-
);
1169+
throw new TransformationFailedException('Unable to reverse value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(), $exception->getCode(), $exception);
11961170
}
11971171

11981172
return $value;

FormConfigBuilder.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -821,11 +821,7 @@ public function setMethod($method)
821821
$upperCaseMethod = strtoupper($method);
822822

823823
if (!\in_array($upperCaseMethod, self::$allowedMethods)) {
824-
throw new InvalidArgumentException(sprintf(
825-
'The form method is "%s", but should be one of "%s".',
826-
$method,
827-
implode('", "', self::$allowedMethods)
828-
));
824+
throw new InvalidArgumentException(sprintf('The form method is "%s", but should be one of "%s".', $method, implode('", "', self::$allowedMethods)));
829825
}
830826

831827
$this->method = $upperCaseMethod;
@@ -892,10 +888,7 @@ public static function validateName($name)
892888
}
893889

894890
if (!self::isValidName($name)) {
895-
throw new InvalidArgumentException(sprintf(
896-
'The name "%s" contains illegal characters. Names should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":").',
897-
$name
898-
));
891+
throw new InvalidArgumentException(sprintf('The name "%s" contains illegal characters. Names should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":").', $name));
899892
}
900893
}
901894

FormErrorIterator.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ public function __construct(FormInterface $form, array $errors)
5050
{
5151
foreach ($errors as $error) {
5252
if (!($error instanceof FormError || $error instanceof self)) {
53-
throw new InvalidArgumentException(sprintf(
54-
'The errors must be instances of '.
55-
'"\Symfony\Component\Form\FormError" or "%s". Got: "%s".',
56-
__CLASS__,
57-
\is_object($error) ? \get_class($error) : \gettype($error)
58-
));
53+
throw new InvalidArgumentException(sprintf('The errors must be instances of "Symfony\Component\Form\FormError" or "%s". Got: "%s".', __CLASS__, \is_object($error) ? \get_class($error) : \gettype($error)));
5954
}
6055
}
6156

ResolvedFormType.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ public function __construct(FormTypeInterface $innerType, array $typeExtensions
8686
// As of Symfony 2.8, getName() returns the FQCN by default
8787
// Otherwise check that the name matches the old naming restrictions
8888
if ($hasCustomName && !preg_match('/^[a-z0-9_]*$/i', $name)) {
89-
throw new InvalidArgumentException(sprintf(
90-
'The "%s" form type name ("%s") is not valid. Names must only contain letters, numbers, and "_".',
91-
\get_class($innerType),
92-
$name
93-
));
89+
throw new InvalidArgumentException(sprintf('The "%s" form type name ("%s") is not valid. Names must only contain letters, numbers, and "_".', \get_class($innerType), $name));
9490
}
9591

9692
foreach ($typeExtensions as $extension) {

Test/FormPerformanceTestCase.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,7 @@ protected function runTest()
3636
$time = microtime(true) - $s;
3737

3838
if (0 != $this->maxRunningTime && $time > $this->maxRunningTime) {
39-
$this->fail(
40-
sprintf(
41-
'expected running time: <= %s but was: %s',
42-
43-
$this->maxRunningTime,
44-
$time
45-
)
46-
);
39+
$this->fail(sprintf('expected running time: <= %s but was: %s', $this->maxRunningTime, $time));
4740
}
4841
}
4942

0 commit comments

Comments
 (0)