Skip to content

Commit 51cb3dd

Browse files
Merge branch '2.8' into 3.4
* 2.8: Consistently throw exceptions on a single line fix fopen calls Update .editorconfig
2 parents 129e1e3 + 82436ba commit 51cb3dd

12 files changed

+19
-93
lines changed

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
@@ -134,9 +134,7 @@ public function reverseTransform($value)
134134
}
135135

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

142140
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
@@ -80,12 +80,7 @@ public function reverseTransform($rfc3339)
8080

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

Extension/Core/DataTransformer/DateTimeToStringTransformer.php

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

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

136131
try {

Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

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

203203
if ('' !== $remainder) {
204-
throw new TransformationFailedException(
205-
sprintf('The number contains unrecognized characters: "%s"', $remainder)
206-
);
204+
throw new TransformationFailedException(sprintf('The number contains unrecognized characters: "%s"', $remainder));
207205
}
208206
}
209207

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/Type/ChoiceType.php

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

129129
// Throw exception if unknown values were submitted
130130
if (\count($unknownValues) > 0) {
131-
throw new TransformationFailedException(sprintf(
132-
'The choices "%s" do not exist in the choice list.',
133-
implode('", "', array_keys($unknownValues))
134-
));
131+
throw new TransformationFailedException(sprintf('The choices "%s" do not exist in the choice list.', implode('", "', array_keys($unknownValues))));
135132
}
136133

137134
$event->setData($data);

Extension/DependencyInjection/DependencyInjectionExtension.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,7 @@ public function getTypeExtensions($name)
8888

8989
// validate result of getExtendedType() to ensure it is consistent with the service definition
9090
if ($extension->getExtendedType() !== $name) {
91-
throw new InvalidArgumentException(
92-
sprintf('The extended type specified for the service "%s" does not match the actual extended type. Expected "%s", given "%s".',
93-
$serviceId,
94-
$name,
95-
$extension->getExtendedType()
96-
)
97-
);
91+
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()));
9892
}
9993
}
10094
}

Form.php

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

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

@@ -863,11 +857,7 @@ public function add($child, $type = null, array $options = array())
863857
$child = $this->config->getFormFactory()->createNamed($child, $type, null, $options);
864858
}
865859
} elseif ($child->getConfig()->getAutoInitialize()) {
866-
throw new RuntimeException(sprintf(
867-
'Automatic initialization is only supported on root forms. You '.
868-
'should set the "auto_initialize" option to false on the field "%s".',
869-
$child->getName()
870-
));
860+
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()));
871861
}
872862

873863
$this->children[$child->getName()] = $child;
@@ -1041,11 +1031,7 @@ private function modelToNorm($value)
10411031
$value = $transformer->transform($value);
10421032
}
10431033
} catch (TransformationFailedException $exception) {
1044-
throw new TransformationFailedException(
1045-
'Unable to transform value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(),
1046-
$exception->getCode(),
1047-
$exception
1048-
);
1034+
throw new TransformationFailedException('Unable to transform value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(), $exception->getCode(), $exception);
10491035
}
10501036

10511037
return $value;
@@ -1069,11 +1055,7 @@ private function normToModel($value)
10691055
$value = $transformers[$i]->reverseTransform($value);
10701056
}
10711057
} catch (TransformationFailedException $exception) {
1072-
throw new TransformationFailedException(
1073-
'Unable to reverse value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(),
1074-
$exception->getCode(),
1075-
$exception
1076-
);
1058+
throw new TransformationFailedException('Unable to reverse value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(), $exception->getCode(), $exception);
10771059
}
10781060

10791061
return $value;
@@ -1104,11 +1086,7 @@ private function normToView($value)
11041086
$value = $transformer->transform($value);
11051087
}
11061088
} catch (TransformationFailedException $exception) {
1107-
throw new TransformationFailedException(
1108-
'Unable to transform value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(),
1109-
$exception->getCode(),
1110-
$exception
1111-
);
1089+
throw new TransformationFailedException('Unable to transform value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(), $exception->getCode(), $exception);
11121090
}
11131091

11141092
return $value;
@@ -1136,11 +1114,7 @@ private function viewToNorm($value)
11361114
$value = $transformers[$i]->reverseTransform($value);
11371115
}
11381116
} catch (TransformationFailedException $exception) {
1139-
throw new TransformationFailedException(
1140-
'Unable to reverse value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(),
1141-
$exception->getCode(),
1142-
$exception
1143-
);
1117+
throw new TransformationFailedException('Unable to reverse value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(), $exception->getCode(), $exception);
11441118
}
11451119

11461120
return $value;

FormConfigBuilder.php

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

793793
if (!\in_array($upperCaseMethod, self::$allowedMethods)) {
794-
throw new InvalidArgumentException(sprintf(
795-
'The form method is "%s", but should be one of "%s".',
796-
$method,
797-
implode('", "', self::$allowedMethods)
798-
));
794+
throw new InvalidArgumentException(sprintf('The form method is "%s", but should be one of "%s".', $method, implode('", "', self::$allowedMethods)));
799795
}
800796

801797
$this->method = $upperCaseMethod;
@@ -862,10 +858,7 @@ public static function validateName($name)
862858
}
863859

864860
if (!self::isValidName($name)) {
865-
throw new InvalidArgumentException(sprintf(
866-
'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 (":").',
867-
$name
868-
));
861+
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));
869862
}
870863
}
871864

0 commit comments

Comments
 (0)