Skip to content

Commit e655120

Browse files
dantleechfabpot
authored andcommitted
Enforce sprintf for exceptions
1 parent 83e078a commit e655120

File tree

34 files changed

+65
-68
lines changed

34 files changed

+65
-68
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDumpReferenceCommand.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8484
}
8585

8686
if (!$extension) {
87-
throw new \LogicException('No extensions with configuration available for "'.$name.'"');
87+
throw new \LogicException(sprintf('No extensions with configuration available for "%s"', $name));
8888
}
8989

9090
$message = 'Default configuration for "'.$name.'"';
@@ -100,7 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
100100
}
101101

102102
if (!$extension) {
103-
throw new \LogicException('No extension with alias "'.$name.'" is enabled');
103+
throw new \LogicException(sprintf('No extension with alias "%s" is enabled', $name));
104104
}
105105

106106
$message = 'Default configuration for extension with alias: "'.$name.'"';
@@ -109,14 +109,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
109109
$configuration = $extension->getConfiguration(array(), $containerBuilder);
110110

111111
if (!$configuration) {
112-
throw new \LogicException('The extension with alias "'.$extension->getAlias().
113-
'" does not have it\'s getConfiguration() method setup');
112+
throw new \LogicException(sprintf('The extension with alias "%s" does not have it\'s getConfiguration() method setup', $extension->getAlias()));
114113
}
115114

116115
if (!$configuration instanceof ConfigurationInterface) {
117-
throw new \LogicException(
118-
'Configuration class "'.get_class($configuration).
119-
'" should implement ConfigurationInterface in order to be dumpable');
116+
throw new \LogicException(sprintf('Configuration class "%s" should implement ConfigurationInterface in order to be dumpable', get_class($configuration)));
120117
}
121118

122119
$output->writeln($message);

src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private function loadFromFile(ContainerBuilder $container, $file, $format)
184184
$loader = new YamlFileLoader($container, $locator);
185185
break;
186186
default:
187-
throw new \InvalidArgumentException('Unsupported format: '.$format);
187+
throw new \InvalidArgumentException(sprintf('Unsupported format: %s', $format));
188188
}
189189

190190
$loader->load($file.'.'.$format);

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ protected function doRequestInProcess($request)
293293
$process->run();
294294

295295
if (!$process->isSuccessful() || !preg_match('/^O\:\d+\:/', $process->getOutput())) {
296-
throw new \RuntimeException('OUTPUT: '.$process->getOutput().' ERROR OUTPUT: '.$process->getErrorOutput());
296+
throw new \RuntimeException(sprintf('OUTPUT: %s ERROR OUTPUT: %s', $process->getOutput(), $process->getErrorOutput()));
297297
}
298298

299299
return unserialize($process->getOutput());

src/Symfony/Component/Console/Formatter/OutputFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function hasStyle($name)
130130
public function getStyle($name)
131131
{
132132
if (!$this->hasStyle($name)) {
133-
throw new \InvalidArgumentException('Undefined style: '.$name);
133+
throw new \InvalidArgumentException(sprintf('Undefined style: %s', $name));
134134
}
135135

136136
return $this->styles[strtolower($name)];

src/Symfony/Component/CssSelector/Parser/Handler/StringHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function handle(Reader $reader, TokenStream $stream)
6464
$match = $reader->findPattern($this->patterns->getQuotedStringPattern($quote));
6565

6666
if (!$match) {
67-
throw new InternalErrorException('Should have found at least an empty match at '.$reader->getPosition().'.');
67+
throw new InternalErrorException(sprintf('Should have found at least an empty match at %s.', $reader->getPosition()));
6868
}
6969

7070
// check unclosed strings

src/Symfony/Component/CssSelector/XPath/Extension/FunctionExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function translateNthChild(XPathExpr $xpath, FunctionNode $function, $las
5858
try {
5959
list($a, $b) = Parser::parseSeries($function->getArguments());
6060
} catch (SyntaxErrorException $e) {
61-
throw new ExpressionErrorException('Invalid series: '.implode(', ', $function->getArguments()), 0, $e);
61+
throw new ExpressionErrorException(sprintf('Invalid series: %s', implode(', ', $function->getArguments())), 0, $e);
6262
}
6363

6464
$xpath->addStarPrefix();

src/Symfony/Component/CssSelector/XPath/Translator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function registerExtension(Extension\ExtensionInterface $extension)
175175
public function getExtension($name)
176176
{
177177
if (!isset($this->extensions[$name])) {
178-
throw new ExpressionErrorException('Extension "'.$name.'" not registered.');
178+
throw new ExpressionErrorException(sprintf('Extension "%s" not registered.', $name));
179179
}
180180

181181
return $this->extensions[$name];
@@ -205,7 +205,7 @@ public function registerParserShortcut(ParserInterface $shortcut)
205205
public function nodeToXPath(NodeInterface $node)
206206
{
207207
if (!isset($this->nodeTranslators[$node->getNodeName()])) {
208-
throw new ExpressionErrorException('Node "'.$node->getNodeName().'" not supported.');
208+
throw new ExpressionErrorException(sprintf('Node "%s" not supported.', $node->getNodeName()));
209209
}
210210

211211
return call_user_func($this->nodeTranslators[$node->getNodeName()], $node);
@@ -223,7 +223,7 @@ public function nodeToXPath(NodeInterface $node)
223223
public function addCombination($combiner, NodeInterface $xpath, NodeInterface $combinedXpath)
224224
{
225225
if (!isset($this->combinationTranslators[$combiner])) {
226-
throw new ExpressionErrorException('Combiner "'.$combiner.'" not supported.');
226+
throw new ExpressionErrorException(sprintf('Combiner "%s" not supported.', $combiner));
227227
}
228228

229229
return call_user_func($this->combinationTranslators[$combiner], $this->nodeToXPath($xpath), $this->nodeToXPath($combinedXpath));
@@ -240,7 +240,7 @@ public function addCombination($combiner, NodeInterface $xpath, NodeInterface $c
240240
public function addFunction(XPathExpr $xpath, FunctionNode $function)
241241
{
242242
if (!isset($this->functionTranslators[$function->getName()])) {
243-
throw new ExpressionErrorException('Function "'.$function->getName().'" not supported.');
243+
throw new ExpressionErrorException(sprintf('Function "%s" not supported.', $function->getName()));
244244
}
245245

246246
return call_user_func($this->functionTranslators[$function->getName()], $xpath, $function);
@@ -257,7 +257,7 @@ public function addFunction(XPathExpr $xpath, FunctionNode $function)
257257
public function addPseudoClass(XPathExpr $xpath, $pseudoClass)
258258
{
259259
if (!isset($this->pseudoClassTranslators[$pseudoClass])) {
260-
throw new ExpressionErrorException('Pseudo-class "'.$pseudoClass.'" not supported.');
260+
throw new ExpressionErrorException(sprintf('Pseudo-class "%s" not supported.', $pseudoClass));
261261
}
262262

263263
return call_user_func($this->pseudoClassTranslators[$pseudoClass], $xpath);
@@ -276,7 +276,7 @@ public function addPseudoClass(XPathExpr $xpath, $pseudoClass)
276276
public function addAttributeMatching(XPathExpr $xpath, $operator, $attribute, $value)
277277
{
278278
if (!isset($this->attributeMatchingTranslators[$operator])) {
279-
throw new ExpressionErrorException('Attribute matcher operator "'.$operator.'" not supported.');
279+
throw new ExpressionErrorException(sprintf('Attribute matcher operator "%s" not supported.', $operator));
280280
}
281281

282282
return call_user_func($this->attributeMatchingTranslators[$operator], $xpath, $attribute, $value);

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ public function setAlias($alias, $id)
640640
}
641641

642642
if ($alias === strtolower($id)) {
643-
throw new InvalidArgumentException('An alias can not reference itself, got a circular reference on "'.$alias.'".');
643+
throw new InvalidArgumentException(sprintf('An alias can not reference itself, got a circular reference on "%s".', $alias));
644644
}
645645

646646
unset($this->definitions[$alias]);

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ private function addNewInstance($id, Definition $definition, $return, $instantia
660660
return sprintf(" $return{$instantiation}%s->%s(%s);\n", $this->getServiceCall($definition->getFactoryService()), $definition->getFactoryMethod(), implode(', ', $arguments));
661661
}
662662

663-
throw new RuntimeException('Factory method requires a factory service or factory class in service definition for '.$id);
663+
throw new RuntimeException(sprintf('Factory method requires a factory service or factory class in service definition for %s', $id));
664664
}
665665

666666
if (false !== strpos($class, '$')) {

src/Symfony/Component/Finder/Adapter/BsdFindAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function buildFormatSorting(Command $command, $sort)
6262
$format = '%m';
6363
break;
6464
default:
65-
throw new \InvalidArgumentException('Unknown sort options: '.$sort.'.');
65+
throw new \InvalidArgumentException(sprintf('Unknown sort options: %s.', $sort));
6666
}
6767

6868
$command

0 commit comments

Comments
 (0)