Skip to content

Commit c7e7111

Browse files
Consistently throw exceptions on a single line
1 parent 6c0f496 commit c7e7111

12 files changed

+23
-107
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/AbstractComparison.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ public function __construct($options = null)
3535
}
3636

3737
if (\is_array($options) && !isset($options['value'])) {
38-
throw new ConstraintDefinitionException(sprintf(
39-
'The %s constraint requires the "value" option to be set.',
40-
\get_class($this)
41-
));
38+
throw new ConstraintDefinitionException(sprintf('The %s constraint requires the "value" option to be set.', \get_class($this)));
4239
}
4340

4441
parent::__construct($options);

Constraints/CallbackValidator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ public function validate($object, Constraint $constraint)
3333
}
3434

3535
if (null !== $constraint->callback && null !== $constraint->methods) {
36-
throw new ConstraintDefinitionException(
37-
'The Callback constraint supports either the option "callback" '.
38-
'or "methods", but not both at the same time.'
39-
);
36+
throw new ConstraintDefinitionException('The Callback constraint supports either the option "callback" or "methods", but not both at the same time.');
4037
}
4138

4239
// has to be an array so that we can differentiate between callables

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/GroupSequence.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ public function offsetGet($offset)
145145
@trigger_error('The '.__METHOD__.' method is deprecated since Symfony 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
146146

147147
if (!isset($this->groups[$offset])) {
148-
throw new OutOfBoundsException(sprintf(
149-
'The offset "%s" does not exist.',
150-
$offset
151-
));
148+
throw new OutOfBoundsException(sprintf('The offset "%s" does not exist.', $offset));
152149
}
153150

154151
return $this->groups[$offset];

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);

Constraints/Valid.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ class Valid extends Constraint
3232
public function __construct($options = null)
3333
{
3434
if (\is_array($options) && array_key_exists('groups', $options)) {
35-
throw new ConstraintDefinitionException(sprintf(
36-
'The option "groups" is not supported by the constraint %s',
37-
__CLASS__
38-
));
35+
throw new ConstraintDefinitionException(sprintf('The option "groups" is not supported by the constraint %s', __CLASS__));
3936
}
4037

4138
if (\is_array($options) && array_key_exists('deep', $options)) {

Mapping/ClassMetadata.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,11 @@ public function getDefaultGroup()
222222
public function addConstraint(Constraint $constraint)
223223
{
224224
if (!\in_array(Constraint::CLASS_CONSTRAINT, (array) $constraint->getTargets())) {
225-
throw new ConstraintDefinitionException(sprintf(
226-
'The constraint "%s" cannot be put on classes.',
227-
\get_class($constraint)
228-
));
225+
throw new ConstraintDefinitionException(sprintf('The constraint "%s" cannot be put on classes.', \get_class($constraint)));
229226
}
230227

231228
if ($constraint instanceof Valid) {
232-
throw new ConstraintDefinitionException(sprintf(
233-
'The constraint "%s" cannot be put on classes.',
234-
\get_class($constraint)
235-
));
229+
throw new ConstraintDefinitionException(sprintf('The constraint "%s" cannot be put on classes.', \get_class($constraint)));
236230
}
237231

238232
if ($constraint instanceof Traverse) {

Mapping/GenericMetadata.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,7 @@ public function __clone()
127127
public function addConstraint(Constraint $constraint)
128128
{
129129
if ($constraint instanceof Traverse) {
130-
throw new ConstraintDefinitionException(sprintf(
131-
'The constraint "%s" can only be put on classes. Please use '.
132-
'"Symfony\Component\Validator\Constraints\Valid" instead.',
133-
\get_class($constraint)
134-
));
130+
throw new ConstraintDefinitionException(sprintf('The constraint "%s" can only be put on classes. Please use "Symfony\Component\Validator\Constraints\Valid" instead.', \get_class($constraint)));
135131
}
136132

137133
if ($constraint instanceof Valid) {

Mapping/MemberMetadata.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ public function accept(ValidationVisitorInterface $visitor, $value, $group, $pro
8989
public function addConstraint(Constraint $constraint)
9090
{
9191
if (!\in_array(Constraint::PROPERTY_CONSTRAINT, (array) $constraint->getTargets())) {
92-
throw new ConstraintDefinitionException(sprintf(
93-
'The constraint %s cannot be put on properties or getters',
94-
\get_class($constraint)
95-
));
92+
throw new ConstraintDefinitionException(sprintf('The constraint %s cannot be put on properties or getters', \get_class($constraint)));
9693
}
9794

9895
parent::addConstraint($constraint);

0 commit comments

Comments
 (0)