Completed
Pull Request — master (#459)
by Vytautas
13:28 queued 09:14
created

MigrationsCommandFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 50
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 18 2
A createService() 0 4 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
19
namespace DoctrineORMModule\Service;
20
21
use Interop\Container\ContainerInterface;
22
use Zend\ServiceManager\FactoryInterface;
23
use Zend\ServiceManager\ServiceLocatorInterface;
24
25
/**
26
 * Service factory for migrations command
27
 *
28
 * @license MIT
29
 * @author Aleksandr Sandrovskiy <[email protected]>
30
 */
31
class MigrationsCommandFactory implements FactoryInterface
32
{
33
    /**
34
     * @var string
35
     */
36
    private $name;
37
38
    /**
39
     * @param $name
40
     */
41 5
    public function __construct($name)
42
    {
43 5
        $this->name = ucfirst(strtolower($name));
44 5
    }
45
46
    /**
47
     * {@inheritDoc}
48
     *
49
     * @return \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand
50
     * @throws \InvalidArgumentException
51
     */
52 5
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
0 ignored issues
show
Unused Code introduced by
The parameter $requestedName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
    {
54 5
        $className = 'Doctrine\DBAL\Migrations\Tools\Console\Command\\' . $this->name . 'Command';
55
56 5
        if (! class_exists($className)) {
57 1
            throw new \InvalidArgumentException();
58
        }
59
60
        // @TODO currently hardcoded: `orm_default` should be injected
61
        /* @var $configuration \Doctrine\DBAL\Migrations\Configuration\Configuration */
62 4
        $configuration = $container->get('doctrine.migrations_configuration.orm_default');
63
        /* @var $command \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand */
64 4
        $command       = new $className;
65
66 4
        $command->setMigrationConfiguration($configuration);
67
68 4
        return $command;
69
    }
70
71
    /**
72
     * @param \Zend\ServiceManager\ServiceLocatorInterface $container
73
     * @return \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand
74
     * @throws \InvalidArgumentException
75
     */
76 5
    public function createService(ServiceLocatorInterface $container)
77
    {
78 5
        return $this($container, 'Doctrine\DBAL\Migrations\Tools\Console\Command\\' . $this->name . 'Command');
79
    }
80
}
81