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
}

0 commit comments

Comments
 (0)