ReinstallCommand::execute()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 30
ccs 0
cts 25
cp 0
rs 8.8571
c 1
b 0
f 1
cc 2
eloc 20
nc 2
nop 2
crap 6
1
<?php
2
3
/**
4
 * This file is part of Packy.
5
 *
6
 * (c) Peter Nijssen
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace AppBundle\Command;
13
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\ArrayInput;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Symfony\Component\Console\Question\ConfirmationQuestion;
19
20
class ReinstallCommand extends Command
21
{
22
    /**
23
     * Configure the command.
24
     */
25
    protected function configure()
26
    {
27
        $this
28
            ->setName('packy:reinstall')
29
            ->setDescription('Reinstall packy');
30
    }
31
32
    /**
33
     * Execute the command.
34
     *
35
     * @param InputInterface  $input
36
     * @param OutputInterface $output
37
     *
38
     * @throws \Exception
39
     */
40
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42
        $helper = $this->getHelper('question');
43
        $question = new ConfirmationQuestion(
44
            'Do you really want to reinstall packy? All data will be lost. (y/n) ',
45
            false
46
        );
47
48
        if (!$helper->ask($input, $output, $question)) {
49
            return;
50
        }
51
52
        $command = $this->getApplication()->find('doctrine:database:drop');
53
        $arguments = [
54
            'command' => 'doctrine:database:drop',
55
            '--force' => true,
56
            '--quiet' => true,
57
        ];
58
59
        $input = new ArrayInput($arguments);
60
        $input->setInteractive(false);
61
        $command->run($input, $output);
62
63
        $installCommand = $this->getApplication()->find('packy:install');
64
        $arguments = [
65
            'command' => 'packy:install',
66
        ];
67
        $installInput = new ArrayInput($arguments);
68
        $installCommand->run($installInput, $output);
69
    }
70
}
71