Completed
Pull Request — master (#11)
by Petr
03:43
created

DoctrineAwareTrait::setDoctrineRegistry()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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
     * @var Registry
17
     */
18
    protected $doctrineRegistry;
19
20
    public function setDoctrineRegistry(Registry $doctrineRegistry)
21
    {
22
        $this->doctrineRegistry = $doctrineRegistry;
23
    }
24
25
    /**
26
     * Shortcut to return the Doctrine EntityManager.
27
     *
28
     * @throws LogicException If DoctrineBundle is not available
29
     */
30
    protected function getDoctrine() : Registry
31
    {
32
        if (is_null($this->doctrineRegistry)) {
33
            throw new LogicException('The DoctrineBundle is not registered in your application.');
34
        }
35
36
        return $this->doctrineRegistry;
37
    }
38
}
39