Skip to content

Commit bd395fa

Browse files
dantleechfabpot
authored andcommitted
Enforce sprintf for exceptions
1 parent 4667a46 commit bd395fa

File tree

8 files changed

+13
-13
lines changed

8 files changed

+13
-13
lines changed

Constraints/All.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public function __construct($options = null)
3636

3737
foreach ($this->constraints as $constraint) {
3838
if (!$constraint instanceof Constraint) {
39-
throw new ConstraintDefinitionException('The value '.$constraint.' is not an instance of Constraint in constraint '.__CLASS__);
39+
throw new ConstraintDefinitionException(sprintf('The value %s is not an instance of Constraint in constraint %s', $constraint, __CLASS__));
4040
}
4141

4242
if ($constraint instanceof Valid) {
43-
throw new ConstraintDefinitionException('The constraint Valid cannot be nested inside constraint '.__CLASS__.'. You can only declare the Valid constraint directly on a field or method.');
43+
throw new ConstraintDefinitionException(sprintf('The constraint Valid cannot be nested inside constraint %s. You can only declare the Valid constraint directly on a field or method.', __CLASS__));
4444
}
4545
}
4646
}

Constraints/Collection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct($options = null)
4343
parent::__construct($options);
4444

4545
if (!is_array($this->fields)) {
46-
throw new ConstraintDefinitionException('The option "fields" is expected to be an array in constraint '.__CLASS__);
46+
throw new ConstraintDefinitionException(sprintf('The option "fields" is expected to be an array in constraint %s', __CLASS__));
4747
}
4848

4949
foreach ($this->fields as $fieldName => $field) {
@@ -57,11 +57,11 @@ public function __construct($options = null)
5757

5858
foreach ($field->constraints as $constraint) {
5959
if (!$constraint instanceof Constraint) {
60-
throw new ConstraintDefinitionException('The value '.$constraint.' of the field '.$fieldName.' is not an instance of Constraint in constraint '.__CLASS__);
60+
throw new ConstraintDefinitionException(sprintf('The value %s of the field %s is not an instance of Constraint in constraint %s', $constraint, $fieldName, __CLASS__));
6161
}
6262

6363
if ($constraint instanceof Valid) {
64-
throw new ConstraintDefinitionException('The constraint Valid cannot be nested inside constraint '.__CLASS__.'. You can only declare the Valid constraint directly on a field or method.');
64+
throw new ConstraintDefinitionException(sprintf('The constraint Valid cannot be nested inside constraint %s. You can only declare the Valid constraint directly on a field or method.', __CLASS__));
6565
}
6666
}
6767
}

Constraints/Count.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct($options = null)
3939
parent::__construct($options);
4040

4141
if (null === $this->min && null === $this->max) {
42-
throw new MissingOptionsException('Either option "min" or "max" must be given for constraint '.__CLASS__, array('min', 'max'));
42+
throw new MissingOptionsException(sprintf('Either option "min" or "max" must be given for constraint %s', __CLASS__), array('min', 'max'));
4343
}
4444
}
4545
}

Constraints/Length.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct($options = null)
4040
parent::__construct($options);
4141

4242
if (null === $this->min && null === $this->max) {
43-
throw new MissingOptionsException('Either option "min" or "max" must be given for constraint '.__CLASS__, array('min', 'max'));
43+
throw new MissingOptionsException(sprintf('Either option "min" or "max" must be given for constraint %s', __CLASS__), array('min', 'max'));
4444
}
4545
}
4646
}

Constraints/Range.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct($options = null)
3232
parent::__construct($options);
3333

3434
if (null === $this->min && null === $this->max) {
35-
throw new MissingOptionsException('Either option "min" or "max" must be given for constraint '.__CLASS__, array('min', 'max'));
35+
throw new MissingOptionsException(sprintf('Either option "min" or "max" must be given for constraint %s', __CLASS__), array('min', 'max'));
3636
}
3737
}
3838
}

Constraints/Valid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Valid extends Constraint
2828
public function __construct($options = null)
2929
{
3030
if (is_array($options) && array_key_exists('groups', $options)) {
31-
throw new ConstraintDefinitionException('The option "groups" is not supported by the constraint '.__CLASS__);
31+
throw new ConstraintDefinitionException(sprintf('The option "groups" is not supported by the constraint %s', __CLASS__));
3232
}
3333

3434
parent::__construct($options);

Mapping/ClassMetadataFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct(LoaderInterface $loader = null, CacheInterface $cach
4949
public function getMetadataFor($value)
5050
{
5151
if (!is_object($value) && !is_string($value)) {
52-
throw new NoSuchMetadataException('Cannot create metadata for non-objects. Got: '.gettype($value));
52+
throw new NoSuchMetadataException(sprintf('Cannot create metadata for non-objects. Got: %s', gettype($value)));
5353
}
5454

5555
$class = ltrim(is_object($value) ? get_class($value) : $value, '\\');
@@ -63,7 +63,7 @@ public function getMetadataFor($value)
6363
}
6464

6565
if (!class_exists($class) && !interface_exists($class)) {
66-
throw new NoSuchMetadataException('The class or interface "'.$class.'" does not exist.');
66+
throw new NoSuchMetadataException(sprintf('The class or interface "%s" does not exist.', $class));
6767
}
6868

6969
$metadata = new ClassMetadata($class);

Tests/Fixtures/FakeMetadataFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public function getMetadataFor($class)
2626
}
2727

2828
if (!is_string($class)) {
29-
throw new NoSuchMetadataException('No metadata for type '.gettype($class));
29+
throw new NoSuchMetadataException(sprintf('No metadata for type %s', gettype($class)));
3030
}
3131

3232
if (!isset($this->metadatas[$class])) {
33-
throw new NoSuchMetadataException('No metadata for "'.$class.'"');
33+
throw new NoSuchMetadataException(sprintf('No metadata for "%s"', $class));
3434
}
3535

3636
return $this->metadatas[$class];

0 commit comments

Comments
 (0)