Skip to content

Commit fce7735

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 6d1ea3c + c7e7111 commit fce7735

File tree

7 files changed

+16
-78
lines changed

7 files changed

+16
-78
lines changed

Constraint.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ abstract class Constraint
7070
public static function getErrorName($errorCode)
7171
{
7272
if (!isset(static::$errorNames[$errorCode])) {
73-
throw new InvalidArgumentException(sprintf(
74-
'The error code "%s" does not exist for constraint of type "%s".',
75-
$errorCode,
76-
\get_called_class()
77-
));
73+
throw new InvalidArgumentException(sprintf('The error code "%s" does not exist for constraint of type "%s".', $errorCode, \get_called_class()));
7874
}
7975

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

139135
if (null === $option) {
140-
throw new ConstraintDefinitionException(
141-
sprintf('No default option is configured for constraint %s', \get_class($this))
142-
);
136+
throw new ConstraintDefinitionException(sprintf('No default option is configured for constraint %s', \get_class($this)));
143137
}
144138

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

153147
if (\count($invalidOptions) > 0) {
154-
throw new InvalidOptionsException(
155-
sprintf('The options "%s" do not exist in constraint %s', implode('", "', $invalidOptions), \get_class($this)),
156-
$invalidOptions
157-
);
148+
throw new InvalidOptionsException(sprintf('The options "%s" do not exist in constraint %s', implode('", "', $invalidOptions), \get_class($this)), $invalidOptions);
158149
}
159150

160151
if (\count($missingOptions) > 0) {
161-
throw new MissingOptionsException(
162-
sprintf('The options "%s" must be set for constraint %s', implode('", "', array_keys($missingOptions)), \get_class($this)),
163-
array_keys($missingOptions)
164-
);
152+
throw new MissingOptionsException(sprintf('The options "%s" must be set for constraint %s', implode('", "', array_keys($missingOptions)), \get_class($this)), array_keys($missingOptions));
165153
}
166154
}
167155

Constraints/Composite.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,7 @@ public function __construct($options = null)
9999
$excessGroups = array_diff($constraint->groups, $this->groups);
100100

101101
if (\count($excessGroups) > 0) {
102-
throw new ConstraintDefinitionException(sprintf(
103-
'The group(s) "%s" passed to the constraint %s '.
104-
'should also be passed to its containing constraint %s',
105-
implode('", "', $excessGroups),
106-
\get_class($constraint),
107-
\get_class($this)
108-
));
102+
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)));
109103
}
110104
} else {
111105
$constraint->groups = $this->groups;

Constraints/Traverse.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ class Traverse extends Constraint
2626
public function __construct($options = null)
2727
{
2828
if (\is_array($options) && array_key_exists('groups', $options)) {
29-
throw new ConstraintDefinitionException(sprintf(
30-
'The option "groups" is not supported by the constraint %s',
31-
__CLASS__
32-
));
29+
throw new ConstraintDefinitionException(sprintf('The option "groups" is not supported by the constraint %s', __CLASS__));
3330
}
3431

3532
parent::__construct($options);

Mapping/ClassMetadata.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,11 @@ public function getDefaultGroup()
180180
public function addConstraint(Constraint $constraint)
181181
{
182182
if (!\in_array(Constraint::CLASS_CONSTRAINT, (array) $constraint->getTargets())) {
183-
throw new ConstraintDefinitionException(sprintf(
184-
'The constraint "%s" cannot be put on classes.',
185-
\get_class($constraint)
186-
));
183+
throw new ConstraintDefinitionException(sprintf('The constraint "%s" cannot be put on classes.', \get_class($constraint)));
187184
}
188185

189186
if ($constraint instanceof Valid) {
190-
throw new ConstraintDefinitionException(sprintf(
191-
'The constraint "%s" cannot be put on classes.',
192-
\get_class($constraint)
193-
));
187+
throw new ConstraintDefinitionException(sprintf('The constraint "%s" cannot be put on classes.', \get_class($constraint)));
194188
}
195189

196190
if ($constraint instanceof Traverse) {

Mapping/GenericMetadata.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,7 @@ public function __clone()
122122
public function addConstraint(Constraint $constraint)
123123
{
124124
if ($constraint instanceof Traverse) {
125-
throw new ConstraintDefinitionException(sprintf(
126-
'The constraint "%s" can only be put on classes. Please use '.
127-
'"Symfony\Component\Validator\Constraints\Valid" instead.',
128-
\get_class($constraint)
129-
));
125+
throw new ConstraintDefinitionException(sprintf('The constraint "%s" can only be put on classes. Please use "Symfony\Component\Validator\Constraints\Valid" instead.', \get_class($constraint)));
130126
}
131127

132128
if ($constraint instanceof Valid && null === $constraint->groups) {

Mapping/MemberMetadata.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ public function __construct($class, $name, $property)
7272
public function addConstraint(Constraint $constraint)
7373
{
7474
if (!\in_array(Constraint::PROPERTY_CONSTRAINT, (array) $constraint->getTargets())) {
75-
throw new ConstraintDefinitionException(sprintf(
76-
'The constraint %s cannot be put on properties or getters',
77-
\get_class($constraint)
78-
));
75+
throw new ConstraintDefinitionException(sprintf('The constraint %s cannot be put on properties or getters', \get_class($constraint)));
7976
}
8077

8178
parent::addConstraint($constraint);

Validator/RecursiveContextualValidator.php

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,7 @@ public function validate($value, $constraints = null, $groups = null)
161161
return $this;
162162
}
163163

164-
throw new RuntimeException(sprintf(
165-
'Cannot validate values of type "%s" automatically. Please '.
166-
'provide a constraint.',
167-
\gettype($value)
168-
));
164+
throw new RuntimeException(sprintf('Cannot validate values of type "%s" automatically. Please provide a constraint.', \gettype($value)));
169165
}
170166

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

178174
if (!$classMetadata instanceof ClassMetadataInterface) {
179-
throw new ValidatorException(sprintf(
180-
'The metadata factory should return instances of '.
181-
'"\Symfony\Component\Validator\Mapping\ClassMetadataInterface", '.
182-
'got: "%s".',
183-
\is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)
184-
));
175+
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)));
185176
}
186177

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

227218
if (!$classMetadata instanceof ClassMetadataInterface) {
228-
throw new ValidatorException(sprintf(
229-
'The metadata factory should return instances of '.
230-
'"\Symfony\Component\Validator\Mapping\ClassMetadataInterface", '.
231-
'got: "%s".',
232-
\is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)
233-
));
219+
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)));
234220
}
235221

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

330316
if (!$classMetadata instanceof ClassMetadataInterface) {
331-
throw new UnsupportedMetadataException(sprintf(
332-
'The metadata factory should return instances of '.
333-
'"Symfony\Component\Validator\Mapping\ClassMetadataInterface", '.
334-
'got: "%s".',
335-
\is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)
336-
));
317+
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)));
337318
}
338319

339320
$this->validateClassNode(
@@ -555,12 +536,7 @@ private function validateClassNode($object, $cacheKey, ClassMetadataInterface $m
555536
// returns two metadata objects, not just one
556537
foreach ($metadata->getPropertyMetadata($propertyName) as $propertyMetadata) {
557538
if (!$propertyMetadata instanceof PropertyMetadataInterface) {
558-
throw new UnsupportedMetadataException(sprintf(
559-
'The property metadata instances should implement '.
560-
'"Symfony\Component\Validator\Mapping\PropertyMetadataInterface", '.
561-
'got: "%s".',
562-
\is_object($propertyMetadata) ? \get_class($propertyMetadata) : \gettype($propertyMetadata)
563-
));
539+
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)));
564540
}
565541

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

598574
// If TRAVERSE, fail if we have no Traversable
599575
if (!$object instanceof \Traversable) {
600-
throw new ConstraintDefinitionException(sprintf(
601-
'Traversal was enabled for "%s", but this class '.
602-
'does not implement "\Traversable".',
603-
\get_class($object)
604-
));
576+
throw new ConstraintDefinitionException(sprintf('Traversal was enabled for "%s", but this class does not implement "\Traversable".', \get_class($object)));
605577
}
606578

607579
$this->validateEachObjectIn(

0 commit comments

Comments
 (0)