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

CriteriaFactoryAbstractFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 7
Ratio 43.75 %

Importance

Changes 0
Metric Value
dl 7
loc 16
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 3
1
<?php
2
3
namespace T4web\DomainModule\Infrastructure;
4
5
use Zend\ServiceManager\Factory\AbstractFactoryInterface;
6
use Interop\Container\ContainerInterface;
7
use T4webInfrastructure\CriteriaFactory;
8
9
/**
10
 * Create Service by template:
11
 *   MODULE-NAME\ENTITY-NAME\Infrastructure\CriteriaFactory
12
 *
13
 * @package T4web\DomainModule\Infrastructure
14
 */
15
class CriteriaFactoryAbstractFactory implements AbstractFactoryInterface
16
{
17
    public function canCreate(ContainerInterface $container, $requestedName)
18
    {
19
        return substr($requestedName, -strlen('Infrastructure\CriteriaFactory')) == 'Infrastructure\CriteriaFactory';
20
    }
21
22
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
23
    {
24
        $namespace = strstr($requestedName, 'Infrastructure\CriteriaFactory', true);
25
26
        $namespaceParts = explode('\\', trim($namespace, "\\"));
27
28 View Code Duplication
        if (count($namespaceParts) > 1) {
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...
29
            list($moduleName, $entityName) = $namespaceParts;
30
            $config = $container->get("$moduleName\\$entityName\\Infrastructure\\Config");
31
        } else {
32
            $entityName = $namespaceParts[0];
33
            $config = $container->get("$entityName\\Infrastructure\\Config");
34
        }
35
36
        return new CriteriaFactory($config);
37
    }
38
}
39