Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96f58e3

Browse files
committed
bug #9624 [Console] Fix undefined offset when formatting namespace suggestions (GromNaN)
This PR was submitted for the master branch but it was merged into the 2.4 branch instead (closes #9624). Discussion ---------- [Console] Fix undefined offset when formatting namespace suggestions [`preg_grep`](http://www.php.net/manual/en/function.preg-grep.php) returns an array indexed using the keys from the input array. `array_values` is used in the method `find`, but was missing in `findNamespace`. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #9614 | License | MIT | Doc PR | n/a Edit: should be merged to 2.4 Commits ------- f5c4011 [Console] Fix undefined offset when formatting namespace suggestions
2 parents 990267f + f2d4b32 commit 96f58e3

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,8 @@ public function findNamespace($namespace)
515515
}
516516

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

522522
return $exact ? $namespace : reset($namespaces);

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public static function setUpBeforeClass()
4444
require_once self::$fixturesPath.'/Foo4Command.php';
4545
require_once self::$fixturesPath.'/Foo5Command.php';
4646
require_once self::$fixturesPath.'/FoobarCommand.php';
47+
require_once self::$fixturesPath.'/BarBucCommand.php';
4748
}
4849

4950
protected function normalizeLineBreaks($text)
@@ -207,6 +208,7 @@ public function testFindNamespace()
207208
public function testFindAmbiguousNamespace()
208209
{
209210
$application = new Application();
211+
$application->add(new \BarBucCommand());
210212
$application->add(new \FooCommand());
211213
$application->add(new \Foo2Command());
212214
$application->findNamespace('f');
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Command\Command;
4+
5+
class BarBucCommand extends Command
6+
{
7+
protected function configure()
8+
{
9+
$this->setName('bar:buc');
10+
}
11+
}

0 commit comments

Comments
 (0)