CommandRemoveCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 4 1
A execute() 0 20 2
1
<?php
2
3
namespace Startwind\Inventorio\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\ArrayInput;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\NullOutput;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class CommandRemoveCommand extends InventorioCommand
13
{
14
    protected static $defaultName = 'command:remove';
15
    protected static $defaultDescription = 'Remove a command to the remote console';
16
17
    protected function configure(): void
18
    {
19
        $this->addArgument('commandId', InputArgument::REQUIRED, 'The commands ID (see command:list)');
20
        parent::configure();
21
    }
22
23
    /**
24
     * @inheritDoc
25
     */
26
    protected function execute(InputInterface $input, OutputInterface $output): int
27
    {
28
        $this->initConfiguration($input->getOption('configFile'));
29
30
        $commands = $this->config->getCommands();
31
32
        $id = $input->getArgument('commandId');
33
34
        if (!array_key_exists($id, $commands)) {
35
            $output->writeln('The given id is not known.');
36
            return Command::FAILURE;
37
        }
38
39
        $this->config->removeCommand($id);
40
41
        $this->getApplication()->find('collect')->run(new ArrayInput([]), new NullOutput());
42
43
        $output->writeln('<info>Command successfully removed</info>');
44
45
        return Command::SUCCESS;
46
    }
47
}
48