Completed
Push — master ( 126914...10d409 )
by
unknown
02:45
created

MigrateAllCommandFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 2
1
<?php
2
/**
3
 * Reddogs (https://github.com/reddogs-at)
4
 *
5
 * @see https://github.com/reddogs-at/reddogs-doctrine-migrations for the canonical source repository
6
 * @license https://github.com/reddogs-at/reddogs-doctrine-migrations/blob/master/LICENSE MIT License
7
 */
8
namespace Reddogs\Doctrine\Migrations;
9
10
use Doctrine\DBAL\Migrations\Configuration\Configuration;
11
use Doctrine\DBAL\Migrations\Migration;
12
use Doctrine\ORM\EntityManager;
13
use Interop\Container\ContainerInterface;
14
use Zend\ServiceManager\Factory\FactoryInterface;
15
16
class MigrateAllCommandFactory implements FactoryInterface
17
{
18
    /**
19
     * Get command
20
     *
21
     * {@inheritdoc}
22
     *
23
     * @see \Zend\ServiceManager\Factory\FactoryInterface::__invoke()
24
     * @return MigrateAllCommand
25
     */
26
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
27
    {
28
        $config = $container->get('config');
29
        $connection = $container->get(EntityManager::class)->getConnection();
30
        $configurations = [];
31
        $migrations = [];
32
        foreach ($config['doctrine']['reddogs_doctrine_migrations'] as $key => $moduleConfig) {
33
            $configurations[$key] = new Configuration($connection);
34
            $configurations[$key]->setMigrationsTableName($moduleConfig['table_name']);
35
            $configurations[$key]->setMigrationsDirectory($moduleConfig['directory']);
36
            $configurations[$key]->setMigrationsNamespace($moduleConfig['namespace']);
37
            $migrations[$key] = new Migration($configurations[$key]);
38
        }
39
        return new MigrateAllCommand($configurations, $migrations);
40
    }
41
}