Skip to content

Commit

Permalink
Merge branch '4.1'
Browse files Browse the repository at this point in the history
* 4.1:
  [DI] configure inlined services before injecting them when dumping the container
  Consistently throw exceptions on a single line
  fix fopen calls
  Update .editorconfig
  • Loading branch information
nicolas-grekas committed Sep 8, 2018
2 parents 1c346e0 + 3adcbe6 commit 0bf5902
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 78 deletions.
20 changes: 4 additions & 16 deletions Constraint.php
Expand Up @@ -70,11 +70,7 @@ abstract class Constraint
public static function getErrorName($errorCode)
{
if (!isset(static::$errorNames[$errorCode])) {
throw new InvalidArgumentException(sprintf(
'The error code "%s" does not exist for constraint of type "%s".',
$errorCode,
\get_called_class()
));
throw new InvalidArgumentException(sprintf('The error code "%s" does not exist for constraint of type "%s".', $errorCode, \get_called_class()));
}

return static::$errorNames[$errorCode];
Expand Down Expand Up @@ -137,9 +133,7 @@ public function __construct($options = null)
$option = $this->getDefaultOption();

if (null === $option) {
throw new ConstraintDefinitionException(
sprintf('No default option is configured for constraint %s', \get_class($this))
);
throw new ConstraintDefinitionException(sprintf('No default option is configured for constraint %s', \get_class($this)));
}

if (array_key_exists($option, $knownOptions)) {
Expand All @@ -151,17 +145,11 @@ public function __construct($options = null)
}

if (\count($invalidOptions) > 0) {
throw new InvalidOptionsException(
sprintf('The options "%s" do not exist in constraint %s', implode('", "', $invalidOptions), \get_class($this)),
$invalidOptions
);
throw new InvalidOptionsException(sprintf('The options "%s" do not exist in constraint %s', implode('", "', $invalidOptions), \get_class($this)), $invalidOptions);
}

if (\count($missingOptions) > 0) {
throw new MissingOptionsException(
sprintf('The options "%s" must be set for constraint %s', implode('", "', array_keys($missingOptions)), \get_class($this)),
array_keys($missingOptions)
);
throw new MissingOptionsException(sprintf('The options "%s" must be set for constraint %s', implode('", "', array_keys($missingOptions)), \get_class($this)), array_keys($missingOptions));
}
}

Expand Down
8 changes: 1 addition & 7 deletions Constraints/Composite.php
Expand Up @@ -99,13 +99,7 @@ public function __construct($options = null)
$excessGroups = array_diff($constraint->groups, $this->groups);

if (\count($excessGroups) > 0) {
throw new ConstraintDefinitionException(sprintf(
'The group(s) "%s" passed to the constraint %s '.
'should also be passed to its containing constraint %s',
implode('", "', $excessGroups),
\get_class($constraint),
\get_class($this)
));
throw new ConstraintDefinitionException(sprintf('The group(s) "%s" passed to the constraint %s should also be passed to its containing constraint %s', implode('", "', $excessGroups), \get_class($constraint), \get_class($this)));
}
} else {
$constraint->groups = $this->groups;
Expand Down
5 changes: 1 addition & 4 deletions Constraints/Traverse.php
Expand Up @@ -26,10 +26,7 @@ class Traverse extends Constraint
public function __construct($options = null)
{
if (\is_array($options) && array_key_exists('groups', $options)) {
throw new ConstraintDefinitionException(sprintf(
'The option "groups" is not supported by the constraint %s',
__CLASS__
));
throw new ConstraintDefinitionException(sprintf('The option "groups" is not supported by the constraint %s', __CLASS__));
}

parent::__construct($options);
Expand Down
10 changes: 2 additions & 8 deletions Mapping/ClassMetadata.php
Expand Up @@ -175,17 +175,11 @@ public function getDefaultGroup()
public function addConstraint(Constraint $constraint)
{
if (!\in_array(Constraint::CLASS_CONSTRAINT, (array) $constraint->getTargets())) {
throw new ConstraintDefinitionException(sprintf(
'The constraint "%s" cannot be put on classes.',
\get_class($constraint)
));
throw new ConstraintDefinitionException(sprintf('The constraint "%s" cannot be put on classes.', \get_class($constraint)));
}

if ($constraint instanceof Valid) {
throw new ConstraintDefinitionException(sprintf(
'The constraint "%s" cannot be put on classes.',
\get_class($constraint)
));
throw new ConstraintDefinitionException(sprintf('The constraint "%s" cannot be put on classes.', \get_class($constraint)));
}

if ($constraint instanceof Traverse) {
Expand Down
6 changes: 1 addition & 5 deletions Mapping/GenericMetadata.php
Expand Up @@ -122,11 +122,7 @@ public function __clone()
public function addConstraint(Constraint $constraint)
{
if ($constraint instanceof Traverse) {
throw new ConstraintDefinitionException(sprintf(
'The constraint "%s" can only be put on classes. Please use '.
'"Symfony\Component\Validator\Constraints\Valid" instead.',
\get_class($constraint)
));
throw new ConstraintDefinitionException(sprintf('The constraint "%s" can only be put on classes. Please use "Symfony\Component\Validator\Constraints\Valid" instead.', \get_class($constraint)));
}

if ($constraint instanceof Valid && null === $constraint->groups) {
Expand Down
5 changes: 1 addition & 4 deletions Mapping/MemberMetadata.php
Expand Up @@ -72,10 +72,7 @@ public function __construct(string $class, string $name, string $property)
public function addConstraint(Constraint $constraint)
{
if (!\in_array(Constraint::PROPERTY_CONSTRAINT, (array) $constraint->getTargets())) {
throw new ConstraintDefinitionException(sprintf(
'The constraint %s cannot be put on properties or getters',
\get_class($constraint)
));
throw new ConstraintDefinitionException(sprintf('The constraint %s cannot be put on properties or getters', \get_class($constraint)));
}

parent::addConstraint($constraint);
Expand Down
40 changes: 6 additions & 34 deletions Validator/RecursiveContextualValidator.php
Expand Up @@ -161,11 +161,7 @@ public function validate($value, $constraints = null, $groups = null)
return $this;
}

throw new RuntimeException(sprintf(
'Cannot validate values of type "%s" automatically. Please '.
'provide a constraint.',
\gettype($value)
));
throw new RuntimeException(sprintf('Cannot validate values of type "%s" automatically. Please provide a constraint.', \gettype($value)));
}

/**
Expand All @@ -176,12 +172,7 @@ public function validateProperty($object, $propertyName, $groups = null)
$classMetadata = $this->metadataFactory->getMetadataFor($object);

if (!$classMetadata instanceof ClassMetadataInterface) {
throw new ValidatorException(sprintf(
'The metadata factory should return instances of '.
'"\Symfony\Component\Validator\Mapping\ClassMetadataInterface", '.
'got: "%s".',
\is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)
));
throw new ValidatorException(sprintf('The metadata factory should return instances of "\Symfony\Component\Validator\Mapping\ClassMetadataInterface", got: "%s".', \is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)));
}

$propertyMetadatas = $classMetadata->getPropertyMetadata($propertyName);
Expand Down Expand Up @@ -225,12 +216,7 @@ public function validatePropertyValue($objectOrClass, $propertyName, $value, $gr
$classMetadata = $this->metadataFactory->getMetadataFor($objectOrClass);

if (!$classMetadata instanceof ClassMetadataInterface) {
throw new ValidatorException(sprintf(
'The metadata factory should return instances of '.
'"\Symfony\Component\Validator\Mapping\ClassMetadataInterface", '.
'got: "%s".',
\is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)
));
throw new ValidatorException(sprintf('The metadata factory should return instances of "\Symfony\Component\Validator\Mapping\ClassMetadataInterface", got: "%s".', \is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)));
}

$propertyMetadatas = $classMetadata->getPropertyMetadata($propertyName);
Expand Down Expand Up @@ -328,12 +314,7 @@ private function validateObject($object, $propertyPath, array $groups, $traversa
$classMetadata = $this->metadataFactory->getMetadataFor($object);

if (!$classMetadata instanceof ClassMetadataInterface) {
throw new UnsupportedMetadataException(sprintf(
'The metadata factory should return instances of '.
'"Symfony\Component\Validator\Mapping\ClassMetadataInterface", '.
'got: "%s".',
\is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)
));
throw new UnsupportedMetadataException(sprintf('The metadata factory should return instances of "Symfony\Component\Validator\Mapping\ClassMetadataInterface", got: "%s".', \is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)));
}

$this->validateClassNode(
Expand Down Expand Up @@ -555,12 +536,7 @@ private function validateClassNode($object, $cacheKey, ClassMetadataInterface $m
// returns two metadata objects, not just one
foreach ($metadata->getPropertyMetadata($propertyName) as $propertyMetadata) {
if (!$propertyMetadata instanceof PropertyMetadataInterface) {
throw new UnsupportedMetadataException(sprintf(
'The property metadata instances should implement '.
'"Symfony\Component\Validator\Mapping\PropertyMetadataInterface", '.
'got: "%s".',
\is_object($propertyMetadata) ? \get_class($propertyMetadata) : \gettype($propertyMetadata)
));
throw new UnsupportedMetadataException(sprintf('The property metadata instances should implement "Symfony\Component\Validator\Mapping\PropertyMetadataInterface", got: "%s".', \is_object($propertyMetadata) ? \get_class($propertyMetadata) : \gettype($propertyMetadata)));
}

$propertyValue = $propertyMetadata->getPropertyValue($object);
Expand Down Expand Up @@ -597,11 +573,7 @@ private function validateClassNode($object, $cacheKey, ClassMetadataInterface $m

// If TRAVERSE, fail if we have no Traversable
if (!$object instanceof \Traversable) {
throw new ConstraintDefinitionException(sprintf(
'Traversal was enabled for "%s", but this class '.
'does not implement "\Traversable".',
\get_class($object)
));
throw new ConstraintDefinitionException(sprintf('Traversal was enabled for "%s", but this class does not implement "\Traversable".', \get_class($object)));
}

$this->validateEachObjectIn(
Expand Down

0 comments on commit 0bf5902

Please sign in to comment.