EntityManagerConsumerTrait::setEntityManager()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * @file
4
 * Contains TheSportsDb\Entity\EntityManagerConsumerTrait.
5
 */
6
namespace TheSportsDb\Entity;
7
8
use TheSportsDb\Entity\EntityManagerInterface;
9
10
/**
11
 * A trait to use by entity manager consumers.
12
 *
13
 * @author Jelle Sebreghts
14
 */
15
trait EntityManagerConsumerTrait {
16
17
  /**
18
   * The entity manager.
19
   *
20
   * @var \TheSportsDb\Entity\EntityManagerInterface
21
   */
22
  protected $entityManager;
23
24
  /**
25
   * Set the entity manager.
26
   *
27
   * @param \TheSportsDb\Entity\EntityManagerInterface $entityManager
28
   *   The entity manager to set.
29
   *
30
   * @throws \Exception
31
   *   If the entity manager is already set.
32
   */
33 2
  public function setEntityManager(EntityManagerInterface $entityManager) {
34 2
    if ($this->entityManager instanceof EntityManagerInterface) {
35 2
      throw new \Exception('Entity manager already set.');
36
    }
37 1
    $this->entityManager = $entityManager;
38 1
  }
39
}
40