Completed
Pull Request — master (#1600)
by
unknown
01:24
created

Status   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 4
dl 0
loc 62
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() 0 27 7
1
<?php
2
/**
3
 * Phinx
4
 *
5
 * (The MIT license)
6
 * Copyright (c) 2015 Rob Morgan
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated * documentation files (the "Software"), to
10
 * deal in the Software without restriction, including without limitation the
11
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
 * sell copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
 * IN THE SOFTWARE.
25
 *
26
 * @package    Phinx
27
 * @subpackage Phinx\Console
28
 */
29
namespace Phinx\Console\Command;
30
31
use Symfony\Component\Console\Input\InputInterface;
32
use Symfony\Component\Console\Input\InputOption;
33
use Symfony\Component\Console\Output\OutputInterface;
34
35
class Status extends AbstractCommand
36
{
37
    protected static $defaultName = 'status';
38
39
    /**
40 35
     * {@inheritdoc}
41
     */
42 35
    protected function configure()
43
    {
44 35
        parent::configure();
45
46 35
        $this->addOption('--environment', '-e', InputOption::VALUE_REQUIRED, 'The target environment.');
47 35
48 35
        $this->setDescription('Show migration status')
49 35
            ->addOption('--format', '-f', InputOption::VALUE_REQUIRED, 'The output format: text or json. Defaults to text.')
50
            ->setHelp(
51
                <<<EOT
52
The <info>status</info> command prints a list of all migrations, along with their current status
53
54
<info>phinx status -e development</info>
55
<info>phinx status -e development -f json</info>
56
57
The <info>version_order</info> configuration option is used to determine the order of the status migrations.
58 35
EOT
59 35
            );
60
    }
61
62
    /**
63
     * Show the migration status.
64
     *
65
     * @param \Symfony\Component\Console\Input\InputInterface $input
66
     * @param \Symfony\Component\Console\Output\OutputInterface $output
67
     * @return int 0 if all migrations are up, or an error code
68 4
     */
69
    protected function execute(InputInterface $input, OutputInterface $output)
70 4
    {
71
        $this->bootstrap($input, $output);
72 4
73 4
        $environment = $input->getOption('environment');
74
        $format = $input->getOption('format');
75 4
76 3
        if ($environment === null) {
77 3
            $environment = $this->getConfig()->getDefaultEnvironment();
78 3
            if (!$input->hasParameterOption('--pipe')) {
79 1
                $output->writeln('<comment>warning</comment> no environment specified, defaulting to: ' . $environment);
80
            }
81 4
82 1
        } elseif(!$input->hasParameterOption('--pipe')) {
83 1
            $output->writeln('<info>using environment</info> ' . $environment);
84
        }
85 4
        if (!$input->hasParameterOption('--pipe') && $format !== null) {
86
            $output->writeln('<info>using format</info> ' . $format);
87
        }
88 4
89
        if (!$input->hasParameterOption('--pipe')) {
90
            $output->writeln('<info>ordering by </info>' . $this->getConfig()->getVersionOrder() . " time");
91
        }
92
93
        // print the status
94
        return $this->getManager()->printStatus($environment, $format);
95
    }
96
}
97