Completed
Pull Request — master (#2)
by Joao
03:57
created

UpdateCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 38
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 10 10 1
B execute() 24 24 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 UpdateCommand 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('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