MigrationServiceProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 13

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 13
dl 0
loc 66
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B register() 0 52 6
A boot() 0 4 1
1
<?php
2
3
namespace Dbtlr\MigrationProvider\Provider;
4
5
use Doctrine\DBAL\Migrations\Configuration\Configuration;
6
use Doctrine\DBAL\Migrations\Tools\Console\Command;
7
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
8
use Silex\ServiceProviderInterface;
9
use Silex\Application;
10
use Knp\Console\ConsoleEvents;
11
use Knp\Console\ConsoleEvent;
12
use Symfony\Component\Console\Helper\DialogHelper;
13
use Symfony\Component\Console\Helper\HelperSet;
14
15
class MigrationServiceProvider implements ServiceProviderInterface
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
16
{
17
    /**
18
     * @param Application $app
19
     */
20
    public function register(Application $app)
21
    {
22
        $app['db.migrations.namespace'] = 'DoctrineMigrations';
23
        $app['db.migrations.path'] = null;
24
        $app['db.migrations.table_name'] = null;
25
        $app['db.migrations.name'] = null;
26
27
        $app['dispatcher']->addListener(ConsoleEvents::INIT, function (ConsoleEvent $event) use ($app) {
28
            $application = $event->getApplication();
29
30
            $helpers = array('dialog' => new DialogHelper());
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\Console\Helper\DialogHelper has been deprecated with message: since version 2.5, to be removed in 3.0. Use {@link \Symfony\Component\Console\Helper\QuestionHelper} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
31
32
            if (isset($app['orm.em'])) {
33
                $helpers['em'] = new EntityManagerHelper($app['orm.em']);
34
            }
35
36
            $helperSet = new HelperSet($helpers);
37
38
            $application->setHelperSet($helperSet);
39
40
            $config = new Configuration($app['db']);
41
            $config->setMigrationsNamespace($app['db.migrations.namespace']);
42
43
            if ($app['db.migrations.path']) {
44
                $config->setMigrationsDirectory($app['db.migrations.path']);
45
                $config->registerMigrationsFromDirectory($app['db.migrations.path']);
46
            }
47
48
            if ($app['db.migrations.name']) {
49
                $config->setName($app['db.migrations.name']);
50
            }
51
52
            if ($app['db.migrations.table_name']) {
53
                $config->setMigrationsTableName($app['db.migrations.table_name']);
54
            }
55
56
            $commands = array(
57
                new Command\DiffCommand(),
58
                new Command\ExecuteCommand(),
59
                new Command\GenerateCommand(),
60
                new Command\MigrateCommand(),
61
                new Command\StatusCommand(),
62
                new Command\VersionCommand(),
63
            );
64
65
            foreach ($commands as $command) {
66
                /** @var \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand $command */
67
                $command->setMigrationConfiguration($config);
68
                $application->add($command);
69
            }
70
        });
71
    }
72
73
    /**
74
     * @param Application $app
75
     */
76
    public function boot(Application $app)
77
    {
78
79
    }
80
}
81