ResolverByModuleContextMapFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 4
dl 34
loc 34
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 23 23 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\ModuleOptions\ModuleOptionsPluginManagerInterface;
12
use Nnx\Container\Options\ModuleOptions;
13
use Nnx\EntryNameResolver\ResolverByModuleContextMap as BaseResolverByModuleContextMap;
14
15
16
/**
17
 * Class ResolverByModuleContextMapFactory
18
 *
19
 * @package Nnx\Container\EntryNameResolver
20
 */
21 View Code Duplication
class ResolverByModuleContextMapFactory 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...
22
{
23
    /**
24
     * @inheritdoc
25
     *
26
     * @param ServiceLocatorInterface $serviceLocator
27
     *
28
     * @return ResolverByModuleContextMap
29
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
30
     */
31
    public function createService(ServiceLocatorInterface $serviceLocator)
32
    {
33
        $appServiceLocator = $serviceLocator;
34
        if ($serviceLocator instanceof AbstractPluginManager) {
35
            $appServiceLocator = $serviceLocator->getServiceLocator();
36
        }
37
38
        /** @var ModuleOptionsPluginManagerInterface $moduleOptionsPluginManager */
39
        $moduleOptionsPluginManager = $appServiceLocator->get(ModuleOptionsPluginManagerInterface::class);
40
41
        /** @var ModuleOptions $moduleOptions */
42
        $moduleOptions = $moduleOptionsPluginManager->get(ModuleOptions::class);
43
        $contextMap = $moduleOptions->getContextMap();
44
45
        $creationOptions = [
46
            'contextMap' => $contextMap,
47
            'className' => ResolverByModuleContextMap::class
48
        ];
49
50
        $entryNameResolverChain = $serviceLocator->get(BaseResolverByModuleContextMap::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 52 which is incompatible with the return type documented by Nnx\Container\EntryNameR...pFactory::createService of type Nnx\Container\EntryNameR...olverByModuleContextMap.
Loading history...
51
52
        return $entryNameResolverChain;
53
    }
54
}
55