Code Duplication    Length = 36-38 lines in 3 locations

src/Console/DownCommand.php 1 location

@@ 15-51 (lines=37) @@
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Question\ConfirmationQuestion;
14
15
class DownCommand extends ConsoleCommand
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

src/Console/UpCommand.php 1 location

@@ 15-50 (lines=36) @@
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Question\ConfirmationQuestion;
14
15
class UpCommand extends ConsoleCommand
16
{
17
    protected function configure()
18
    {
19
        parent::configure(); 
20
        $this
21
            ->setName('up')
22
            ->setDescription('Migrate Up 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->up($this->upTo, true);
46
        } catch (\Exception $ex) {
47
            $this->handleError($ex, $output);
48
        }
49
    }
50
}
51

src/Console/UpdateCommand.php 1 location

@@ 15-52 (lines=38) @@
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Question\ConfirmationQuestion;
14
15
class UpdateCommand extends ConsoleCommand
16
{
17
    protected function configure()
18
    {
19
        parent::configure(); 
20
        $this
21
            ->setName('update')
22
            ->setDescription('Migrate Up or Down the database version based on the current database version and the ' .
23
                'migration scripts available'
24
            );
25
26
    }
27
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        try {
31
            $versionInfo = $this->migration->getCurrentVersion();
32
            if (strpos($versionInfo['status'], 'partial') !== false) {
33
                $helper = $this->getHelper('question');
34
                $question = new ConfirmationQuestion(
35
                    'The database was not fully updated and maybe be unstable. Did you really want migrate the version? (y/N) ',
36
                    false
37
                );
38
39
                if (!$helper->ask($input, $output, $question)) {
40
                    $output->writeln('Aborted.');
41
42
                    return;
43
                }
44
            }
45
46
            parent::execute($input, $output);
47
            $this->migration->update($this->upTo, true);
48
        } catch (\Exception $ex) {
49
            $this->handleError($ex, $output);
50
        }
51
    }
52
}
53