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

MigrationsCommandFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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