Completed
Push — master ( f4f9e6...43b9e4 )
by Андрей
03:53 queued 01:46
created

DefaultEntryNameResolverFactory::createService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 12

Duplication

Lines 23
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 23
loc 23
rs 9.0856
cc 2
eloc 12
nc 2
nop 1
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/container
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\Container\EntryNameResolver;
7
8
use Zend\ServiceManager\AbstractPluginManager;
9
use Zend\ServiceManager\FactoryInterface;
10
use Zend\ServiceManager\ServiceLocatorInterface;
11
use Nnx\EntryNameResolver\EntryNameResolverChain;
12
use Nnx\ModuleOptions\ModuleOptionsPluginManagerInterface;
13
use Nnx\Container\Options\ModuleOptions;
14
15
/**
16
 * Class DefaultEntryNameResolverFactory
17
 *
18
 * @package Nnx\Container\EntryNameResolver
19
 */
20 View Code Duplication
class DefaultEntryNameResolverFactory implements FactoryInterface
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...
21
{
22
    /**
23
     * @inheritdoc
24
     *
25
     * @param ServiceLocatorInterface $serviceLocator
26
     *
27
     * @return DefaultEntryNameResolver
28
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
29
     */
30
    public function createService(ServiceLocatorInterface $serviceLocator)
31
    {
32
        $appServiceLocator = $serviceLocator;
33
        if ($serviceLocator instanceof AbstractPluginManager) {
34
            $appServiceLocator = $serviceLocator->getServiceLocator();
35
        }
36
37
        /** @var ModuleOptionsPluginManagerInterface $moduleOptionsPluginManager */
38
        $moduleOptionsPluginManager = $appServiceLocator->get(ModuleOptionsPluginManagerInterface::class);
39
40
        /** @var ModuleOptions $moduleOptions */
41
        $moduleOptions = $moduleOptionsPluginManager->get(ModuleOptions::class);
42
        $entryNameResolversConfig = $moduleOptions->getEntryNameResolvers();
43
44
        $creationOptions = [
45
            'resolvers' => $entryNameResolversConfig,
46
            'className' => DefaultEntryNameResolver::class
47
        ];
48
49
        $entryNameResolverChain = $serviceLocator->get(EntryNameResolverChain::class, $creationOptions);
0 ignored issues
show
Unused Code introduced by
The call to ServiceLocatorInterface::get() has too many arguments starting with $creationOptions.

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...
Bug Compatibility introduced by
The expression $serviceLocator->get(\Nn...ass, $creationOptions); of type object|array adds the type array to the return on line 51 which is incompatible with the return type documented by Nnx\Container\EntryNameR...rFactory::createService of type Nnx\Container\EntryNameR...efaultEntryNameResolver.
Loading history...
50
51
        return $entryNameResolverChain;
52
    }
53
}
54