Skip to content

Commit

Permalink
Fix undefined offset when formatting namespace suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN authored and fabpot committed Nov 27, 2013
1 parent 990267f commit f2d4b32
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Application.php
Expand Up @@ -515,8 +515,8 @@ public function findNamespace($namespace)
}

$exact = in_array($namespace, $namespaces, true);
if (1 < count($namespaces) && !$exact) {
throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions($namespaces)));
if (count($namespaces) > 1 && !$exact) {
throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))));
}

return $exact ? $namespace : reset($namespaces);
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -44,6 +44,7 @@ public static function setUpBeforeClass()
require_once self::$fixturesPath.'/Foo4Command.php';
require_once self::$fixturesPath.'/Foo5Command.php';
require_once self::$fixturesPath.'/FoobarCommand.php';
require_once self::$fixturesPath.'/BarBucCommand.php';
}

protected function normalizeLineBreaks($text)
Expand Down Expand Up @@ -207,6 +208,7 @@ public function testFindNamespace()
public function testFindAmbiguousNamespace()
{
$application = new Application();
$application->add(new \BarBucCommand());
$application->add(new \FooCommand());
$application->add(new \Foo2Command());
$application->findNamespace('f');
Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/Console/Tests/Fixtures/BarBucCommand.php
@@ -0,0 +1,11 @@
<?php

use Symfony\Component\Console\Command\Command;

class BarBucCommand extends Command
{
protected function configure()
{
$this->setName('bar:buc');
}
}

0 comments on commit f2d4b32

Please sign in to comment.