Skip to content

Commit

Permalink
Merge branch '2.8' into 3.4
Browse files Browse the repository at this point in the history
* 2.8:
  Consistently throw exceptions on a single line
  fix fopen calls
  Update .editorconfig
  • Loading branch information
nicolas-grekas committed Sep 8, 2018
2 parents 129e1e3 + 82436ba commit 51cb3dd
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 93 deletions.
4 changes: 1 addition & 3 deletions Extension/Core/DataTransformer/ArrayToPartsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ public function reverseTransform($array)
return;
}

throw new TransformationFailedException(
sprintf('The keys "%s" should not be empty', implode('", "', $emptyKeys)
));
throw new TransformationFailedException(sprintf('The keys "%s" should not be empty', implode('", "', $emptyKeys)));
}

return $result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ public function reverseTransform($value)
}

if (\count($emptyFields) > 0) {
throw new TransformationFailedException(
sprintf('The fields "%s" should not be empty', implode('", "', $emptyFields)
));
throw new TransformationFailedException(sprintf('The fields "%s" should not be empty', implode('", "', $emptyFields)));
}

if (isset($value['month']) && !ctype_digit((string) $value['month'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,7 @@ public function reverseTransform($rfc3339)

if (preg_match('/(\d{4})-(\d{2})-(\d{2})/', $rfc3339, $matches)) {
if (!checkdate($matches[2], $matches[3], $matches[1])) {
throw new TransformationFailedException(sprintf(
'The date "%s-%s-%s" is not a valid date.',
$matches[1],
$matches[2],
$matches[3]
));
throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,7 @@ public function reverseTransform($value)
$lastErrors = \DateTime::getLastErrors();

if (0 < $lastErrors['warning_count'] || 0 < $lastErrors['error_count']) {
throw new TransformationFailedException(
implode(', ', array_merge(
array_values($lastErrors['warnings']),
array_values($lastErrors['errors'])
))
);
throw new TransformationFailedException(implode(', ', array_merge(array_values($lastErrors['warnings']), array_values($lastErrors['errors']))));
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ public function reverseTransform($value)
$remainder = trim($remainder, " \t\n\r\0\x0b\xc2\xa0");

if ('' !== $remainder) {
throw new TransformationFailedException(
sprintf('The number contains unrecognized characters: "%s"', $remainder)
);
throw new TransformationFailedException(sprintf('The number contains unrecognized characters: "%s"', $remainder));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ public function reverseTransform($array)
foreach ($this->keys as $key) {
if (isset($array[$key]) && '' !== $array[$key] && false !== $array[$key] && array() !== $array[$key]) {
if ($array[$key] !== $result) {
throw new TransformationFailedException(
'All values in the array should be the same'
);
throw new TransformationFailedException('All values in the array should be the same');
}
} else {
$emptyKeys[] = $key;
Expand All @@ -79,9 +77,7 @@ public function reverseTransform($array)
return;
}

throw new TransformationFailedException(
sprintf('The keys "%s" should not be empty', implode('", "', $emptyKeys)
));
throw new TransformationFailedException(sprintf('The keys "%s" should not be empty', implode('", "', $emptyKeys)));
}

return $result;
Expand Down
5 changes: 1 addition & 4 deletions Extension/Core/Type/ChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)

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

$event->setData($data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,7 @@ public function getTypeExtensions($name)

// validate result of getExtendedType() to ensure it is consistent with the service definition
if ($extension->getExtendedType() !== $name) {
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()
)
);
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()));
}
}
}
Expand Down
38 changes: 6 additions & 32 deletions Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,7 @@ public function setData($modelData)
? 'an instance of class '.\get_class($viewData)
: 'a(n) '.\gettype($viewData);

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.'.'
);
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.'.');
}
}

Expand Down Expand Up @@ -863,11 +857,7 @@ public function add($child, $type = null, array $options = array())
$child = $this->config->getFormFactory()->createNamed($child, $type, null, $options);
}
} elseif ($child->getConfig()->getAutoInitialize()) {
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()
));
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()));
}

$this->children[$child->getName()] = $child;
Expand Down Expand Up @@ -1041,11 +1031,7 @@ private function modelToNorm($value)
$value = $transformer->transform($value);
}
} catch (TransformationFailedException $exception) {
throw new TransformationFailedException(
'Unable to transform value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(),
$exception->getCode(),
$exception
);
throw new TransformationFailedException('Unable to transform value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(), $exception->getCode(), $exception);
}

return $value;
Expand All @@ -1069,11 +1055,7 @@ private function normToModel($value)
$value = $transformers[$i]->reverseTransform($value);
}
} catch (TransformationFailedException $exception) {
throw new TransformationFailedException(
'Unable to reverse value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(),
$exception->getCode(),
$exception
);
throw new TransformationFailedException('Unable to reverse value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(), $exception->getCode(), $exception);
}

return $value;
Expand Down Expand Up @@ -1104,11 +1086,7 @@ private function normToView($value)
$value = $transformer->transform($value);
}
} catch (TransformationFailedException $exception) {
throw new TransformationFailedException(
'Unable to transform value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(),
$exception->getCode(),
$exception
);
throw new TransformationFailedException('Unable to transform value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(), $exception->getCode(), $exception);
}

return $value;
Expand Down Expand Up @@ -1136,11 +1114,7 @@ private function viewToNorm($value)
$value = $transformers[$i]->reverseTransform($value);
}
} catch (TransformationFailedException $exception) {
throw new TransformationFailedException(
'Unable to reverse value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(),
$exception->getCode(),
$exception
);
throw new TransformationFailedException('Unable to reverse value for property path "'.$this->getPropertyPath().'": '.$exception->getMessage(), $exception->getCode(), $exception);
}

return $value;
Expand Down
11 changes: 2 additions & 9 deletions FormConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,7 @@ public function setMethod($method)
$upperCaseMethod = strtoupper($method);

if (!\in_array($upperCaseMethod, self::$allowedMethods)) {
throw new InvalidArgumentException(sprintf(
'The form method is "%s", but should be one of "%s".',
$method,
implode('", "', self::$allowedMethods)
));
throw new InvalidArgumentException(sprintf('The form method is "%s", but should be one of "%s".', $method, implode('", "', self::$allowedMethods)));
}

$this->method = $upperCaseMethod;
Expand Down Expand Up @@ -862,10 +858,7 @@ public static function validateName($name)
}

if (!self::isValidName($name)) {
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
));
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));
}
}

Expand Down
7 changes: 1 addition & 6 deletions FormErrorIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ public function __construct(FormInterface $form, array $errors)
{
foreach ($errors as $error) {
if (!($error instanceof FormError || $error instanceof self)) {
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)
));
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)));
}
}

Expand Down
9 changes: 1 addition & 8 deletions Test/FormPerformanceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,7 @@ protected function runTest()
$time = microtime(true) - $s;

if (0 != $this->maxRunningTime && $time > $this->maxRunningTime) {
$this->fail(
sprintf(
'expected running time: <= %s but was: %s',

$this->maxRunningTime,
$time
)
);
$this->fail(sprintf('expected running time: <= %s but was: %s', $this->maxRunningTime, $time));
}
}

Expand Down

0 comments on commit 51cb3dd

Please sign in to comment.