Skip to content

Commit e4decb4

Browse files
dantleechfabpot
authored andcommitted
Enforce sprintf for exceptions
1 parent f99ace6 commit e4decb4

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

Extension/Core/ChoiceList/ChoiceList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,13 @@ protected function addChoice(array &$bucketForPreferred, array &$bucketForRemain
345345
$index = $this->createIndex($choice);
346346

347347
if ('' === $index || null === $index || !FormConfigBuilder::isValidName((string) $index)) {
348-
throw new InvalidConfigurationException('The index "'.$index.'" created by the choice list is invalid. It should be a valid, non-empty Form name.');
348+
throw new InvalidConfigurationException(sprintf('The index "%s" created by the choice list is invalid. It should be a valid, non-empty Form name.', $index));
349349
}
350350

351351
$value = $this->createValue($choice);
352352

353353
if (!is_string($value)) {
354-
throw new InvalidConfigurationException('The value created by the choice list is of type "'.gettype($value).'", but should be a string.');
354+
throw new InvalidConfigurationException(sprintf('The value created by the choice list is of type "%s", but should be a string.', gettype($value)));
355355
}
356356

357357
$view = new ChoiceView($choice, $value, $label);

Extension/Core/ChoiceList/LazyChoiceList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private function load()
141141
$choiceList = $this->loadChoiceList();
142142

143143
if (!$choiceList instanceof ChoiceListInterface) {
144-
throw new Exception('loadChoiceList() should return a ChoiceListInterface instance. Got '.gettype($choiceList));
144+
throw new Exception(sprintf('loadChoiceList() should return a ChoiceListInterface instance. Got %s', gettype($choiceList)));
145145
}
146146

147147
$this->choiceList = $choiceList;

Extension/Core/ChoiceList/ObjectChoiceList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private function extractLabels($choices, array &$labels)
176176
} elseif (method_exists($choice, '__toString')) {
177177
$labels[$i] = (string) $choice;
178178
} else {
179-
throw new StringCastException('A "__toString()" method was not found on the objects of type "'.get_class($choice).'" passed to the choice field. To read a custom getter instead, set the argument $labelPath to the desired property path.');
179+
throw new StringCastException(sprintf('A "__toString()" method was not found on the objects of type "%s" passed to the choice field. To read a custom getter instead, set the argument $labelPath to the desired property path.', get_class($choice)));
180180
}
181181
}
182182
}

Extension/Core/DataTransformer/ChoiceToBooleanArrayTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function reverseTransform($values)
9898
if (isset($choices[$i])) {
9999
return $choices[$i] === '' ? null : $choices[$i];
100100
} else {
101-
throw new TransformationFailedException('The choice "'.$i.'" does not exist');
101+
throw new TransformationFailedException(sprintf('The choice "%s" does not exist', $i));
102102
}
103103
}
104104
}

Extension/Core/DataTransformer/ChoiceToValueTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function reverseTransform($value)
5353
$choices = $this->choiceList->getChoicesForValues(array($value));
5454

5555
if (1 !== count($choices)) {
56-
throw new TransformationFailedException('The choice "'.$value.'" does not exist or is not unique');
56+
throw new TransformationFailedException(sprintf('The choice "%s" does not exist or is not unique', $value));
5757
}
5858

5959
$choice = current($choices);

Extension/Core/DataTransformer/ChoicesToBooleanArrayTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function reverseTransform($values)
109109
}
110110

111111
if (count($unknown) > 0) {
112-
throw new TransformationFailedException('The choices "'.implode('", "', $unknown).'" were not found');
112+
throw new TransformationFailedException(sprintf('The choices "%s" were not found', implode('", "', $unknown)));
113113
}
114114

115115
return $result;

Extension/Validator/ViolationMapper/ViolationPath.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function getElements()
155155
public function getElement($index)
156156
{
157157
if (!isset($this->elements[$index])) {
158-
throw new \OutOfBoundsException('The index '.$index.' is not within the violation path');
158+
throw new \OutOfBoundsException(sprintf('The index %s is not within the violation path', $index));
159159
}
160160

161161
return $this->elements[$index];
@@ -167,7 +167,7 @@ public function getElement($index)
167167
public function isProperty($index)
168168
{
169169
if (!isset($this->isIndex[$index])) {
170-
throw new \OutOfBoundsException('The index '.$index.' is not within the violation path');
170+
throw new \OutOfBoundsException(sprintf('The index %s is not within the violation path', $index));
171171
}
172172

173173
return !$this->isIndex[$index];
@@ -179,7 +179,7 @@ public function isProperty($index)
179179
public function isIndex($index)
180180
{
181181
if (!isset($this->isIndex[$index])) {
182-
throw new \OutOfBoundsException('The index '.$index.' is not within the violation path');
182+
throw new \OutOfBoundsException(sprintf('The index %s is not within the violation path', $index));
183183
}
184184

185185
return $this->isIndex[$index];
@@ -206,7 +206,7 @@ public function isIndex($index)
206206
public function mapsForm($index)
207207
{
208208
if (!isset($this->mapsForm[$index])) {
209-
throw new \OutOfBoundsException('The index '.$index.' is not within the violation path');
209+
throw new \OutOfBoundsException(sprintf('The index %s is not within the violation path', $index));
210210
}
211211

212212
return $this->mapsForm[$index];

0 commit comments

Comments
 (0)