Skip to content

Commit

Permalink
Add class to exception message, use sprintf for exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacePossum authored and keradus committed Jun 1, 2015
1 parent 7ef7ea9 commit 4c0bfc9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Symfony/CS/Console/Command/FixCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
2 changes: 1 addition & 1 deletion Symfony/CS/Tests/Tokenizer/AbstractTransformerTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions Symfony/CS/Tokenizer/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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));
}
}

Expand Down
9 changes: 7 additions & 2 deletions Symfony/CS/Tokenizer/Transformers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4c0bfc9

Please sign in to comment.