Completed
Push — master ( 0d0ff5...a726ac )
by Mike
8s
created

ConsoleRunner::createApplication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
ccs 0
cts 9
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 2
crap 2
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\DBAL\Migrations\Tools\Console;
21
22
use Doctrine\DBAL\Migrations\Tools\Console\Command;
23
use Doctrine\DBAL\Migrations\MigrationsVersion;
24
use Symfony\Component\Console\Application;
25
use Symfony\Component\Console\Helper\HelperSet;
26
27
/**
28
 * Handles running the Console Tools inside Symfony Console context.
29
 */
30
class ConsoleRunner
31
{
32
    /**
33
     * Runs console with the given helperset.
34
     *
35
     * @param \Symfony\Component\Console\Helper\HelperSet  $helperSet
36
     * @param \Symfony\Component\Console\Command\Command[] $commands
37
     *
38
     * @return void
39
     */
40
    public static function run(HelperSet $helperSet, $commands = array())
41
    {
42
        $cli = self::createApplication($helperSet, $commands);
43
        $cli->run();
44
    }
45
46
    /**
47
     * Creates a console application with the given helperset and
48
     * optional commands.
49
     *
50
     * @param \Symfony\Component\Console\Helper\HelperSet $helperSet
51
     * @param array $commands
52
     *
53
     * @return \Symfony\Component\Console\Application
54
     */
55
    public static function createApplication(HelperSet $helperSet, $commands = array())
56
    {
57
        $cli = new Application('Doctrine Migrations', MigrationsVersion::VERSION());
58
        $cli->setCatchExceptions(true);
59
        $cli->setHelperSet($helperSet);
60
        self::addCommands($cli);
61
        $cli->addCommands($commands);
62
63
        return $cli;
64
    }
65
66
    /**
67
     * @param Application $cli
68
     *
69
     * @return void
70
     */
71
    public static function addCommands(Application $cli)
72
    {
73
        $cli->addCommands(array(
74
            new Command\ExecuteCommand(),
75
            new Command\GenerateCommand(),
76
            new Command\LatestCommand(),
77
            new Command\MigrateCommand(),
78
            new Command\StatusCommand(),
79
            new Command\VersionCommand(),
80
        ));
81
82
        if ($cli->getHelperSet()->has('em')) {
83
            $cli->add(new Command\DiffCommand());
84
        }
85
    }
86
}
87