DoctrineFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B create() 0 13 5
1
<?php
2
3
namespace Isolate\PersistenceContext\Transaction;
4
5
use Doctrine\Common\Persistence\ManagerRegistry;
6
use Doctrine\ORM\EntityManagerInterface;
7
use Isolate\Exception\UnsupportedManagerException;
8
use Isolate\PersistenceContext;
9
use Isolate\PersistenceContext\Transaction;
10
11
class DoctrineFactory implements Factory
12
{
13
    /**
14
     * @var ManagerRegistry
15
     */
16
    private $managerRegistry;
17
18
    /**
19
     * @param ManagerRegistry $managerRegistry
20
     */
21
    public function __construct(ManagerRegistry $managerRegistry)
22
    {
23
        $this->managerRegistry = $managerRegistry;
24
    }
25
26
    /**
27
     * @param PersistenceContext $context
28
     * @return Doctrine\ODMTransaction|Doctrine\ORMTransaction
29
     * @throws UnsupportedManagerException
30
     */
31
    public function create(PersistenceContext $context)
32
    {
33
        $objectManager = $this->managerRegistry->getManager((string) $context->getName());
34
        if (interface_exists('Doctrine\ORM\EntityManagerInterface') && is_a($objectManager, 'Doctrine\ORM\EntityManagerInterface')) {
35
            return new Transaction\Doctrine\ORMTransaction($objectManager);
0 ignored issues
show
Compatibility introduced by
$objectManager of type object<Doctrine\Common\Persistence\ObjectManager> is not a sub-type of object<Doctrine\ORM\EntityManagerInterface>. It seems like you assume a child interface of the interface Doctrine\Common\Persistence\ObjectManager to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
36
        }
37
38
        if (class_exists('Doctrine\ODM\MongoDB\DocumentManager') && is_a($objectManager, 'Doctrine\ODM\MongoDB\DocumentManager')) {
39
            return new Transaction\Doctrine\ODMTransaction($objectManager);
0 ignored issues
show
Compatibility introduced by
$objectManager of type object<Doctrine\Common\Persistence\ObjectManager> is not a sub-type of object<Doctrine\ODM\MongoDB\DocumentManager>. It seems like you assume a concrete implementation of the interface Doctrine\Common\Persistence\ObjectManager to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
40
        }
41
42
        throw new UnsupportedManagerException(sprintf("Manager \"%s\" is not supported.", get_class($objectManager)));
43
    }
44
}
45