Completed
Push — master ( ab0989...c19db1 )
by mark
13s queued 10s
created

Status   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 7.69 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 4
dl 6
loc 78
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 19 1
B execute() 6 37 6

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
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace Phinx\Console\Command;
9
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
class Status extends AbstractCommand
15
{
16
    /**
17
     * @var string
18
     */
19
    protected static $defaultName = 'status';
20
21
    /**
22
     * {@inheritDoc}
23
     *
24
     * @return void
25
     */
26
    protected function configure()
27
    {
28
        parent::configure();
29
30
        $this->addOption('--environment', '-e', InputOption::VALUE_REQUIRED, 'The target environment.');
31
32
        $this->setDescription('Show migration status')
33
            ->addOption('--format', '-f', InputOption::VALUE_REQUIRED, 'The output format: text or json. Defaults to text.')
34
            ->setHelp(
35
                <<<EOT
36
The <info>status</info> command prints a list of all migrations, along with their current status
37
38
<info>phinx status -e development</info>
39
<info>phinx status -e development -f json</info>
40 35
41
The <info>version_order</info> configuration option is used to determine the order of the status migrations.
42 35
EOT
43
            );
44 35
    }
45
46 35
    /**
47 35
     * Show the migration status.
48 35
     *
49 35
     * @param \Symfony\Component\Console\Input\InputInterface $input
50
     * @param \Symfony\Component\Console\Output\OutputInterface $output
51
     *
52
     * @return int 0 if all migrations are up, or an error code
53
     */
54
    protected function execute(InputInterface $input, OutputInterface $output)
55
    {
56
        $this->bootstrap($input, $output);
57
58 35
        $environment = $input->getOption('environment');
59 35
        $format = $input->getOption('format');
60
61 View Code Duplication
        if ($environment === null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
62
            $environment = $this->getConfig()->getDefaultEnvironment();
63
            $output->writeln('<comment>warning</comment> no environment specified, defaulting to: ' . $environment);
64
        } else {
65
            $output->writeln('<info>using environment</info> ' . $environment);
66
        }
67
68 4
        if (!$this->getConfig()->hasEnvironment($environment)) {
69
            $output->writeln(sprintf('<error>The environment "%s" does not exist</error>', $environment));
70 4
71
            return self::CODE_ERROR;
72 4
        }
73 4
74
        if ($format !== null) {
75 4
            $output->writeln('<info>using format</info> ' . $format);
76 3
        }
77 3
78 3
        $output->writeln('<info>ordering by </info>' . $this->getConfig()->getVersionOrder() . " time");
79 1
80
        // print the status
81 4
        $result = $this->getManager()->printStatus($environment, $format);
82 1
83 1
        if ($result['hasMissingMigration']) {
84
            return self::CODE_STATUS_MISSING;
85 4
        } elseif ($result['hasDownMigration']) {
86
            return self::CODE_STATUS_DOWN;
87
        }
88 4
89
        return self::CODE_SUCCESS;
90
    }
91
}
92