Completed
Push — master ( 0004c8...3efb43 )
by Андрей
04:54 queued 02:11
created

EntityAbstractFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A canCreateServiceWithName() 0 4 1
A createServiceWithName() 0 5 1
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/doctrine
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\Doctrine\EntityManager;
7
8
use Zend\ServiceManager\AbstractFactoryInterface;
9
use Zend\ServiceManager\ServiceLocatorInterface;
10
use ReflectionClass;
11
12
/**
13
 * Class EntityAbstractFactory
14
 *
15
 * @package Nnx\Doctrine\EntityManager
16
 */
17
class EntityAbstractFactory implements AbstractFactoryInterface
18
{
19
    /**
20
     * @inheritdoc
21
     *
22
     * @param ServiceLocatorInterface $serviceLocator
23
     * @param                         $name
24
     * @param                         $requestedName
25
     *
26
     * @return boolean
27
     */
28
    public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
29
    {
30
        return class_exists($requestedName);
31
    }
32
33
34
    /**
35
     * @inheritdoc
36
     *
37
     * @param ServiceLocatorInterface $serviceLocator
38
     * @param                         $name
39
     * @param                         $requestedName
40
     *
41
     * @return mixed
42
     */
43
    public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
44
    {
45
        $r = new ReflectionClass($requestedName);
46
        return $r->newInstance();
47
    }
48
}
49