canCreateServiceWithName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 3
crap 2
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