Completed
Push — master ( 5ff3e1...46578f )
by Jonathan
12s
created

ConsoleRunner::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Tools\Console;
6
7
use Doctrine\Migrations\Tools\Console\Command\AbstractCommand;
8
use Doctrine\Migrations\Tools\Console\Command\DiffCommand;
9
use Doctrine\Migrations\Tools\Console\Command\DumpSchemaCommand;
10
use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand;
11
use Doctrine\Migrations\Tools\Console\Command\GenerateCommand;
12
use Doctrine\Migrations\Tools\Console\Command\LatestCommand;
13
use Doctrine\Migrations\Tools\Console\Command\MigrateCommand;
14
use Doctrine\Migrations\Tools\Console\Command\RollupCommand;
15
use Doctrine\Migrations\Tools\Console\Command\StatusCommand;
16
use Doctrine\Migrations\Tools\Console\Command\UpToDateCommand;
17
use Doctrine\Migrations\Tools\Console\Command\VersionCommand;
18
use PackageVersions\Versions;
19
use Symfony\Component\Console\Application;
20
use Symfony\Component\Console\Helper\HelperSet;
21
22
class ConsoleRunner
23
{
24
    /** @param AbstractCommand[] $commands */
25 1
    public static function run(HelperSet $helperSet, array $commands = []) : void
26
    {
27 1
        $cli = static::createApplication($helperSet, $commands);
28 1
        $cli->run();
29 1
    }
30
31
    /** @param AbstractCommand[] $commands */
32 1
    public static function createApplication(HelperSet $helperSet, array $commands = []) : Application
33
    {
34 1
        $cli = new Application('Doctrine Migrations', Versions::getVersion('doctrine/migrations'));
35 1
        $cli->setCatchExceptions(true);
36 1
        $cli->setHelperSet($helperSet);
37 1
        self::addCommands($cli);
38 1
        $cli->addCommands($commands);
39
40 1
        return $cli;
41
    }
42
43 10
    public static function addCommands(Application $cli) : void
44
    {
45 10
        $cli->addCommands([
46 10
            new DumpSchemaCommand(),
47 10
            new ExecuteCommand(),
48 10
            new GenerateCommand(),
49 10
            new LatestCommand(),
50 10
            new MigrateCommand(),
51 10
            new RollupCommand(),
52 10
            new StatusCommand(),
53 10
            new VersionCommand(),
54 10
            new UpToDateCommand(),
55
        ]);
56
57 10
        if (! $cli->getHelperSet()->has('em')) {
58 9
            return;
59
        }
60
61 1
        $cli->add(new DiffCommand());
62 1
    }
63
}
64