EntityServiceAbstractServiceFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 38
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A canCreate() 0 4 1
A __invoke() 0 6 1
A canCreateServiceWithName() 0 4 1
A createServiceWithName() 0 10 2
1
<?php
2
/**
3
 * Polder Knowledge / entityservice-module (https://polderknowledge.com)
4
 *
5
 * @link https://github.com/polderknowledge/entityservice-module for the canonical source repository
6
 * @copyright Copyright (c) 2016 Polder Knowledge (https://polderknowledge.com)
7
 * @license https://github.com/polderknowledge/entityservice-module/blob/master/LICENSE.md MIT
8
 */
9
10
namespace PolderKnowledge\EntityService\Service;
11
12
use Interop\Container\ContainerInterface;
13
use PolderKnowledge\EntityService\EntityService;
14
use Zend\ServiceManager\AbstractFactoryInterface;
15
use Zend\ServiceManager\ServiceLocatorInterface;
16
17
/**
18
 * Abstract service factory to create a DefaultEntityService
19
 */
20
class EntityServiceAbstractServiceFactory implements AbstractFactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\ServiceManager\AbstractFactoryInterface has been deprecated with message: Use Zend\ServiceManager\Factory\AbstractFactoryInterface 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...
21
{
22
    const REPOSITORY_SERVICE_KEY = 'EntityRepositoryManager';
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 9
    public function canCreate(ContainerInterface $container, $requestedName)
28
    {
29 9
        return class_exists($requestedName);
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 3
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
36
    {
37 3
        $entityRepositoryManager = $container->get(self::REPOSITORY_SERVICE_KEY, $options);
0 ignored issues
show
Unused Code introduced by
The call to ContainerInterface::get() has too many arguments starting with $options.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
38
39 3
        return new EntityService($entityRepositoryManager->get($requestedName), $requestedName);
40
    }
41
42 3
    public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
43
    {
44 3
        return $this->canCreate($serviceLocator, $requestedName);
45
    }
46
47 3
    public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
48
    {
49
        // @codeCoverageIgnoreStart
50
        if (method_exists($serviceLocator, 'getServiceLocator')) {
51
            $serviceLocator = $serviceLocator->getServiceLocator();
52
        }
53
        // @codeCoverageIgnoreEnd
54
55 3
        return $this($serviceLocator, $requestedName);
56
    }
57
}
58