Completed
Push — master ( 3a31a3...e3b547 )
by max
12:05
created

UpdaterAbstractFactory::canCreate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace T4web\DomainModule\Service;
4
5
use Zend\ServiceManager\Factory\AbstractFactoryInterface;
6
use Interop\Container\ContainerInterface;
7
use T4webDomain\Service\Updater;
8
9
/**
10
 * Create Service by template:
11
 *   MODULE-NAME\ENTITY-NAME\Service\Creator
12
 *
13
 * @package T4web\DomainModule\Service
14
 */
15 View Code Duplication
class UpdaterAbstractFactory implements AbstractFactoryInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
16
{
17
    public function canCreate(ContainerInterface $container, $requestedName)
18
    {
19
        return substr($requestedName, -strlen('Service\Updater')) == 'Service\Updater';
20
    }
21
22
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
23
    {
24
        $namespace = strstr($requestedName, 'Service\Updater', true);
25
26
        $namespaceParts = explode('\\', trim($namespace, "\\"));
27
28
        if (count($namespaceParts) > 1) {
29
            list($moduleName, $entityName) = $namespaceParts;
30
            $repository = $container->get("$moduleName\\$entityName\\Infrastructure\\Repository");
31
            $entityEventManager = $serviceManager->get("$moduleName\\$entityName\\EntityEventManager");
0 ignored issues
show
Bug introduced by
The variable $serviceManager does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
32
        } else {
33
            $entityName = $namespaceParts[0];
34
            $repository = $container->get("$entityName\\Infrastructure\\Repository");
35
            $entityEventManager = $serviceManager->get("$entityName\\EntityEventManager");
36
        }
37
38
        return new Updater($repository, $entityEventManager);
39
    }
40
}
41