DiAbstractPluginFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 36.36 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 16
loc 44
wmc 6
lcom 1
cbo 3
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A canCreateServiceWithName() 8 8 2
A createServiceWithName() 8 8 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
namespace mxdiModule\ServiceManager;
3
4
use Zend\ServiceManager\AbstractFactoryInterface;
5
use Zend\ServiceManager\AbstractPluginManager;
6
use Zend\ServiceManager\ServiceLocatorInterface;
7
use mxdiModule\Service\Instantiator;
8
9
/**
10
 * @TODO DELETE THIS FILE BECAUSE IT IS NOT NEEDED
11
 * DEFAULT FACTORY WORKS FOR ABSTRACT MANAGERS AS WELL
12
 */
13
class DiAbstractPluginFactory implements AbstractFactoryInterface
14
{
15
    /** @var DiAbstractFactory */
16
    protected $factory;
17
18 2
    public function __construct(DiAbstractFactory $factory = null)
19
    {
20 2
        $this->factory = $factory ?: new DiAbstractFactory(new Instantiator());
21 2
    }
22
23
    /**
24
     * Determine if we can create a service with name
25
     *
26
     * @param ServiceLocatorInterface $serviceLocator
27
     * @param string $name
28
     * @param string $requestedName
29
     * @return bool
30
     */
31 1 View Code Duplication
    public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
32
    {
33 1
        if ($serviceLocator instanceof AbstractPluginManager) {
34 1
            $serviceLocator = $serviceLocator->getServiceLocator();
35 1
        }
36
37 1
        return $this->factory->canCreateServiceWithName($serviceLocator, $name, $requestedName);
38
    }
39
40
    /**
41
     * Create service with name
42
     *
43
     * @param ServiceLocatorInterface $serviceLocator
44
     * @param string $name
45
     * @param string $requestedName
46
     * @return object
47
     */
48 1 View Code Duplication
    public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
49
    {
50 1
        if ($serviceLocator instanceof AbstractPluginManager) {
51 1
            $serviceLocator = $serviceLocator->getServiceLocator();
52 1
        }
53
54 1
        return $this->factory->createServiceWithName($serviceLocator, $name, $requestedName);
55
    }
56
}
57