Completed
Push — master ( 8b75a3...7680fc )
by Kenneth
02:48
created

ConfigurationFactory::createService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace DoctrineMigrationsModule\Service;
4
5
use Interop\Container\ContainerInterface;
6
use Zend\ServiceManager\FactoryInterface;
7
use Zend\ServiceManager\ServiceLocatorInterface;
8
use DoctrineMigrationsModule\Migrations\Configuration;
9
10
class ConfigurationFactory implements FactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\ServiceManager\FactoryInterface has been deprecated with message: Use Zend\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...
11
{
12
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
13
    {
14
        // Get config.
15
        $config = $container->get('configuration');
16
        $config = $config['doctrine']['migrations'];
17
18 View Code Duplication
        if (isset($config['connection']) && $container->has($config['connection'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
            $connection = $container->get($config['connection']);
20
        } else {
21
            $connection = $container->get('doctrine.connection.orm_default');
22
        }
23
        unset($config['connection']);
24
25 View Code Duplication
        if (isset($config['output_writer']) && $container->has($config['output_writer'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
            $outputWriter = $container->get($config['output_writer']);
27
        } else {
28
            $outputWriter = null;
29
        }
30
        unset($config['output_writer']);
31
32
        $configuration = new Configuration($connection, $outputWriter);
33
34
        foreach ($config as $key => $value) {
35
            $setter = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
36
            if (!method_exists($configuration, $setter)) {
37
                continue;
38
            }
39
            $configuration->{$setter}($value);
40
        }
41
42
        return $configuration;
43
    }
44
45
    /**
46
     * Create service
47
     *
48
     * @param ServiceLocatorInterface $serviceLocator
49
     * @return mixed
50
     */
51
    public function createService(ServiceLocatorInterface $serviceLocator)
52
    {
53
        $config = $serviceLocator->get('configuration');
0 ignored issues
show
Unused Code introduced by
$config is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
54
55
    }
56
}
57