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

DoctrineAwareTrait::getDoctrine()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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