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

DoctrineAwareTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
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 26
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
     * @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