VhostDeleteCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Portiere\Command;
4
5
use Portiere\WebServer\ManagerFactory;
6
use Portiere\WebServer\Vhost;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Console\Style\SymfonyStyle;
12
13
/**
14
 * Class VhostDeleteCommand.
15
 *
16
 * @author Ignacio Velazquez <[email protected]>
17
 */
18
class VhostDeleteCommand extends Command
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23 1
    protected function configure()
24
    {
25 1
        $this
26 1
            ->setName('vhost:delete')
27 1
            ->setDescription('Deletes a vhost from the web server')
28 1
            ->addArgument(
29 1
                'vhostFilename',
30 1
                InputArgument::REQUIRED,
31
                'Vhost filename'
32 1
            );
33 1
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected function execute(InputInterface $input, OutputInterface $output)
39
    {
40
        $io = new SymfonyStyle($input, $output);
41
42
        $vhost = new Vhost($input->getArgument('vhostFilename'));
43
44
        $manager = ManagerFactory::create();
45
46
        $io->warning('The following files are going to be deleted');
47
48
        $io->listing($manager->getGeneratedFiles($vhost));
49
50
        if (!$io->confirm('Do you confirm the removal of the vhost?', true)) {
51
            $io->warning('Canceled!! The vhost has not been deleted due to user interruption');
52
53
            return;
54
        }
55
56
        $manager->deleteVhost($vhost);
57
        $manager->restartServer();
58
59
        $io->success('Awesome!! Your vhost has been successfully deleted');
60
    }
61
}
62