From 4c0bfc9edd0f1152b89fceab462206a061e22824 Mon Sep 17 00:00:00 2001 From: Possum Date: Fri, 29 May 2015 19:20:09 +0200 Subject: [PATCH] Add class to exception message, use sprintf for exceptions --- Symfony/CS/Console/Command/FixCommand.php | 4 ++-- .../CS/Tests/Tokenizer/AbstractTransformerTestBase.php | 2 +- Symfony/CS/Tokenizer/Tokens.php | 6 +++--- Symfony/CS/Tokenizer/Transformers.php | 9 +++++++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Symfony/CS/Console/Command/FixCommand.php b/Symfony/CS/Console/Command/FixCommand.php index 61060c2a1ef..7a3e54783ef 100644 --- a/Symfony/CS/Console/Command/FixCommand.php +++ b/Symfony/CS/Console/Command/FixCommand.php @@ -311,13 +311,13 @@ protected function execute(InputInterface $input, OutputInterface $output) } if (null === $config) { - throw new \InvalidArgumentException(sprintf('The configuration "%s" is not defined', $input->getOption('config'))); + throw new \InvalidArgumentException(sprintf('The configuration "%s" is not defined.', $input->getOption('config'))); } } elseif (file_exists($configFile)) { $config = include $configFile; // verify that the config has an instance of Config if (!$config instanceof Config) { - throw new \UnexpectedValueException(sprintf('The config file "%s" does not return an instance of Symfony\CS\Config\Config', $configFile)); + throw new \UnexpectedValueException(sprintf('The config file "%s" does not return a "Symfony\CS\Config\Config" instance. Got: "%s".', $configFile, is_object($config) ? get_class($config) : gettype($config))); } if ('txt' === $input->getOption('format')) { diff --git a/Symfony/CS/Tests/Tokenizer/AbstractTransformerTestBase.php b/Symfony/CS/Tests/Tokenizer/AbstractTransformerTestBase.php index bab94e48003..a5935fe6459 100644 --- a/Symfony/CS/Tests/Tokenizer/AbstractTransformerTestBase.php +++ b/Symfony/CS/Tests/Tokenizer/AbstractTransformerTestBase.php @@ -49,7 +49,7 @@ protected static function getTransformer() } } - throw new \RuntimeException("Transformer $transformerClass not found."); + throw new \RuntimeException(sprintf('Transformer class "%s" not found.', $transformerClass)); } protected static function getTransformers() diff --git a/Symfony/CS/Tokenizer/Tokens.php b/Symfony/CS/Tokenizer/Tokens.php index 95886da1376..fe4bfde4989 100644 --- a/Symfony/CS/Tokenizer/Tokens.php +++ b/Symfony/CS/Tokenizer/Tokens.php @@ -190,7 +190,7 @@ private static function getBlockEdgeDefinitions() private static function getCache($key) { if (!self::hasCache($key)) { - throw new \OutOfBoundsException('Unknown cache key: '.$key); + throw new \OutOfBoundsException(sprintf('Unknown cache key: %s', $key)); } return self::$cache[$key]; @@ -329,7 +329,7 @@ public function findBlockEnd($type, $searchIndex, $findEnd = true) $blockEdgeDefinitions = self::getBlockEdgeDefinitions(); if (!isset($blockEdgeDefinitions[$type])) { - throw new \InvalidArgumentException('Invalid param $type'); + throw new \InvalidArgumentException(sprintf('Invalid param type: %s', $type)); } $startEdge = $blockEdgeDefinitions[$type]['start']; @@ -791,7 +791,7 @@ public function findSequence(array $sequence, $start = 0, $end = null, $caseSens $token = new Token($token); } if ($token->isWhitespace() || $token->isComment() || $token->isEmpty()) { - throw new \InvalidArgumentException('Non-meaningful token at position: '.$key); + throw new \InvalidArgumentException(sprintf('Non-meaningful token at position: %s', $key)); } } diff --git a/Symfony/CS/Tokenizer/Transformers.php b/Symfony/CS/Tokenizer/Transformers.php index 62bb238b592..ddeb8485c8a 100644 --- a/Symfony/CS/Tokenizer/Transformers.php +++ b/Symfony/CS/Tokenizer/Transformers.php @@ -69,7 +69,7 @@ public static function create() public function getCustomToken($value) { if (!$this->hasCustomToken($value)) { - throw new \InvalidArgumentException("No custom token was found for $value"); + throw new \InvalidArgumentException(sprintf('No custom token was found for: %s', $value)); } return $this->customTokens[$value]; @@ -131,7 +131,12 @@ public function transform(Tokens $tokens) private function addCustomToken($value, $name) { if ($this->hasCustomToken($value)) { - throw new \LogicException("Trying to register token $name ($value), token with this value was already defined: ".$this->getCustomToken($value)); + throw new \LogicException( + sprintf( + 'Trying to register token %s (%s), token with this value was already defined: %s', + $name, $value, $this->getCustomToken($value) + ) + ); } $this->customTokens[$value] = $name;