Completed
Pull Request — master (#11)
by Petr
04:23
created

DoctrineAwareTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 33
ccs 0
cts 11
cp 0
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setDoctrineRegistry() 0 4 1
A getDoctrine() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of Symplify
5
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
6
 */
7
8
namespace Symplify\ControllerAutowire\DependencyInjection;
9
10
use Doctrine\Bundle\DoctrineBundle\Registry;
11
use LogicException;
12
13
trait DoctrineAwareTrait
14
{
15
16
    /**
17
     * @var Registry
18
     */
19
    protected $doctrineRegistry;
20
21
22
    /**
23
     * @param Registry $doctrineRegistry
24
     */
25
    public function setDoctrineRegistry(Registry $doctrineRegistry)
26
    {
27
        $this->doctrineRegistry = $doctrineRegistry;
28
    }
29
30
    /**
31
     * Shortcut to return the Doctrine EntityManager
32
     *
33
     * @return Registry
34
     *
35
     * @throws LogicException If DoctrineBundle is not available
36
     */
37
    protected function getDoctrine() : Registry
38
    {
39
        if (is_null($this->doctrineRegistry)) {
40
            throw new LogicException('The DoctrineBundle is not registered in your application.');
41
        }
42
43
        return $this->doctrineRegistry;
44
    }
45
}
46