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

PhinxApplication::getDefaultInputDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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;
30
31
use Phinx\Console\Command\Breakpoint;
32
use Phinx\Console\Command\Create;
33
use Phinx\Console\Command\Init;
34
use Phinx\Console\Command\Migrate;
35
use Phinx\Console\Command\Rollback;
36
use Phinx\Console\Command\SeedCreate;
37
use Phinx\Console\Command\SeedRun;
38
use Phinx\Console\Command\Status;
39
use Phinx\Console\Command\Test;
40
use Symfony\Component\Console\Application;
41
use Symfony\Component\Console\Input\InputOption;
42
use Symfony\Component\Console\Input\InputInterface;
43
use Symfony\Component\Console\Output\OutputInterface;
44
45
/**
46
 * Phinx console application.
47
 *
48
 * @author Rob Morgan <[email protected]>
49
 */
50 35
class PhinxApplication extends Application
51
{
52 35
    /**
53
     * Class Constructor.
54 35
     *
55 35
     * Initialize the Phinx console application.
56 35
     *
57 35
     * @param string|null $version The Application Version, if null, use version out of composer.json file
58 35
     */
59 35
    public function __construct($version = null)
60 35
    {
61 35
        if ($version === null) {
62 35
            $composerConfig = json_decode(file_get_contents(__DIR__ . '/../../../composer.json'));
63 35
            $version = $composerConfig->version;
64 35
        }
65 35
66
        parent::__construct('Phinx by CakePHP - https://phinx.org.', $version);
67
68
        $this->addCommands([
69
            new Init(),
70
            new Create(),
71
            new Migrate(),
72
            new Rollback(),
73
            new Status(),
74 1
            new Breakpoint(),
75
            new Test(),
76
            new SeedCreate(),
77
            new SeedRun(),
78 1
        ]);
79 1
    }
80 1
81 1
    /**
82
     * {@inheritdoc}
83 1
     */
84
    protected function getDefaultInputDefinition() {
85
        $definition = parent::getDefaultInputDefinition();
86
        $definition->addOption(new InputOption('pipe', null, InputOption::VALUE_NONE, 'Supress non-main console output'));
87
        return $definition;
88
    }
89
90
    /**
91
     * Runs the current application.
92
     *
93
     * @param \Symfony\Component\Console\Input\InputInterface $input An Input instance
94
     * @param \Symfony\Component\Console\Output\OutputInterface $output An Output instance
95
     * @return int 0 if everything went fine, or an error code
96
     */
97
    public function doRun(InputInterface $input, OutputInterface $output)
98
    {
99
        // always show the version information except when the user invokes the help
100
        // command as that already does it
101
        if (!$input->hasParameterOption('--pipe') && (($input->hasParameterOption(['--help', '-h']) !== false) || ($input->getFirstArgument() !== null && $input->getFirstArgument() !== 'list'))) {
102
            $output->writeln($this->getLongVersion());
103
            $output->writeln('');
104
        }
105
106
        return parent::doRun($input, $output);
107
    }
108
}
109