Completed
Push — master ( 9bd1b4...a21c41 )
by Joao
04:25 queued 02:23
created

DownCommand::execute()   B

Complexity

Conditions 4
Paths 13

Size

Total Lines 24
Code Lines 15

Duplication

Lines 24
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 24
loc 24
rs 8.6845
cc 4
eloc 15
nc 13
nop 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: jg
5
 * Date: 17/06/16
6
 * Time: 21:52
7
 */
8
9
namespace ByJG\DbMigration\Console;
10
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Question\ConfirmationQuestion;
14
15 View Code Duplication
class DownCommand extends ConsoleCommand
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
    protected function configure()
18
    {
19
        parent::configure(); 
20
        $this
21
            ->setName('down')
22
            ->setDescription('Migrate down the database version.');
23
24
    }
25
26
    protected function execute(InputInterface $input, OutputInterface $output)
27
    {
28
        try {
29
            $versionInfo = $this->migration->getCurrentVersion();
30
            if (strpos($versionInfo['status'], 'partial') !== false) {
31
                $helper = $this->getHelper('question');
32
                $question = new ConfirmationQuestion(
33
                    'The database was not fully updated and maybe be unstable. Did you really want migrate the version? (y/N)',
34
                    false
35
                );
36
37
                if (!$helper->ask($input, $output, $question)) {
38
                    $output->writeln('Aborted.');
39
40
                    return;
41
                }
42
            }
43
44
            parent::execute($input, $output);
45
            $this->migration->down($this->upTo, true);
46
        } catch (\Exception $ex) {
47
            $this->handleError($ex, $output);
48
        }
49
    }
50
51
}
52