Webmozart\Console\Api\Command\CommandCollection::remove PHP Method

remove() public method

If no such command can be found, the method does nothing.
public remove ( string $name )
$name string The name of the command.
    public function remove($name)
    {
        if (isset($this->aliasIndex[$name])) {
            $this->remove($this->aliasIndex[$name]);
            return;
        }
        if (isset($this->shortNameIndex[$name])) {
            $this->remove($this->shortNameIndex[$name]);
            return;
        }
        unset($this->commands[$name]);
        foreach ($this->shortNameIndex as $shortName => $targetName) {
            if ($name === $targetName) {
                unset($this->shortNameIndex[$shortName]);
            }
        }
        foreach ($this->aliasIndex as $alias => $targetName) {
            if ($name === $targetName) {
                unset($this->aliasIndex[$alias]);
            }
        }
    }

Usage Example

 public function testCount()
 {
     $this->assertCount(0, $this->collection);
     $this->collection->add(new Command(new CommandConfig('ls')));
     $this->assertCount(1, $this->collection);
     $this->collection->add(new Command(new CommandConfig('cd')));
     $this->assertCount(2, $this->collection);
     $this->collection->remove('ls');
     $this->assertCount(1, $this->collection);
     $this->collection->clear();
     $this->assertCount(0, $this->collection);
 }