CommandFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 1
A getMigrationsCommand() 0 6 1
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 Zend\ServiceManager\Factory\FactoryInterface;
11
use Interop\Container\ContainerInterface;
12
use Symfony\Component\Console\Application;
13
use Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand as AbstractMigrationsCommand;
14
use Doctrine\DBAL\Migrations\Configuration\Configuration;
15
use Doctrine\ORM\EntityManager;
16
use Symfony\Component\Console\Output\ConsoleOutput;
17
18
class CommandFactory implements FactoryInterface
19
{
20
21
    /**
22
     * Get command
23
     *
24
     * {@inheritdoc}
25
     *
26
     * @see \Zend\ServiceManager\Factory\FactoryInterface::__invoke()
27
     * @return AbstractCommand
28
     */
29
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
30
    {
31
        $config = $container->get('config');
32
        return new $requestedName(
33
            new Application(),
34
            $this->getMigrationsCommand($requestedName),
35
            new Configuration($container->get(EntityManager::class)->getConnection()),
36
            new ConsoleOutput(),
37
            $config['doctrine']['reddogs_doctrine_migrations']
38
        );
39
    }
40
41
    /**
42
     * Get migrations command
43
     *
44
     * @param string $requestedName
45
     * @return AbstractMigrationsCommand
46
     */
47
    public function getMigrationsCommand($requestedName)
48
    {
49
        $parts = explode('\\', $requestedName);
50
        $class = 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\' . array_pop($parts);
51
        return new $class();
52
    }
53
54
}