Completed
Push — master ( 178c75...b82d68 )
by Luís
11s
created

ConsoleRunner::createApplication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 7
nc 1
nop 2
crap 1
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\MigrationsVersion;
23
use Symfony\Component\Console\Application;
24
use Symfony\Component\Console\Helper\HelperSet;
25
26
/**
27
 * Handles running the Console Tools inside Symfony Console context.
28
 */
29
class ConsoleRunner
30
{
31
    /**
32
     * Runs console with the given helperset.
33
     *
34
     * @param \Symfony\Component\Console\Helper\HelperSet  $helperSet
35
     * @param \Symfony\Component\Console\Command\Command[] $commands
36
     *
37
     * @return void
38
     */
39
    public static function run(HelperSet $helperSet, $commands = [])
40
    {
41
        $cli = self::createApplication($helperSet, $commands);
42
        $cli->run();
43
    }
44
45
    /**
46
     * Creates a console application with the given helperset and
47
     * optional commands.
48
     *
49
     * @param \Symfony\Component\Console\Helper\HelperSet $helperSet
50
     * @param array $commands
51
     *
52
     * @return \Symfony\Component\Console\Application
53
     */
54 1
    public static function createApplication(HelperSet $helperSet, $commands = [])
55
    {
56 1
        $cli = new Application('Doctrine Migrations', MigrationsVersion::VERSION());
57 1
        $cli->setCatchExceptions(true);
58 1
        $cli->setHelperSet($helperSet);
59 1
        self::addCommands($cli);
60 1
        $cli->addCommands($commands);
61
62 1
        return $cli;
63
    }
64
65
    /**
66
     * @param Application $cli
67
     *
68
     * @return void
69
     */
70 10
    public static function addCommands(Application $cli)
71
    {
72 10
        $cli->addCommands([
73 10
            new Command\ExecuteCommand(),
74 10
            new Command\GenerateCommand(),
75 10
            new Command\LatestCommand(),
76 10
            new Command\MigrateCommand(),
77 10
            new Command\StatusCommand(),
78 10
            new Command\VersionCommand(),
79 10
            new Command\UpToDateCommand(),
80
        ]);
81
82 10
        if ($cli->getHelperSet()->has('em')) {
83 1
            $cli->add(new Command\DiffCommand());
84
        }
85 10
    }
86
}
87