Completed
Pull Request — develop (#607)
by Tom
01:30
created

MigrationsCommandFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.5

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 4
cts 8
cp 0.5
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2.5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineORMModule\Service;
6
7
use Doctrine\Migrations\Configuration\Configuration;
8
use Doctrine\Migrations\Tools\Console\Command\AbstractCommand;
9
use Interop\Container\ContainerInterface;
10
use InvalidArgumentException;
11
use Laminas\ServiceManager\FactoryInterface;
12
use Laminas\ServiceManager\ServiceLocatorInterface;
13
use function class_exists;
14
use function strtolower;
15
use function ucfirst;
16
17
/**
18
 * Service factory for migrations command
19
 */
20
class MigrationsCommandFactory implements FactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Laminas\ServiceManager\FactoryInterface has been deprecated with message: Use Laminas\ServiceManager\Factory\FactoryInterface 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...
21
{
22
    /** @var string */
23
    private $name;
24
25 1
    public function __construct(string $name)
26
    {
27 1
        $this->name = ucfirst(strtolower($name));
28 1
    }
29
30
    /**
31
     * {@inheritDoc}
32
     *
33
     * @return AbstractCommand
34
     *
35
     * @throws InvalidArgumentException
36
     */
37 1
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
38
    {
39 1
        $className = 'Doctrine\Migrations\Tools\Console\Command\\' . $this->name . 'Command';
40
41 1
        if (! class_exists($className)) {
42 1
            throw new InvalidArgumentException();
43
        }
44
45
        $configuration = $container->get('doctrine.migrations_configuration.orm_default');
46
        $command = new $className();
47
48
        $command->setMigrationConfiguration($configuration);
49
50
        return $command;
51
    }
52
53
    /**
54
     * @throws InvalidArgumentException
55
     */
56 1
    public function createService(ServiceLocatorInterface $container) : AbstractCommand
57
    {
58 1
        return $this($container, 'Doctrine\Migrations\Tools\Console\Command\\' . $this->name . 'Command');
59
    }
60
}
61