DbService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 50
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getManager() 0 4 1
A fetch() 0 8 2
1
<?php
2
3
namespace Faulancer\Service;
4
5
use Faulancer\Exception\DbException;
6
use ORM\EntityFetcher;
7
use ORM\EntityManager;
8
use Faulancer\ORM\Entity;
9
use Faulancer\ServiceLocator\ServiceInterface;
10
11
/**
12
 * Class DbService
13
 *
14
 * @package Faulancer\Service
15
 * @author  Florian Knapp <[email protected]>
16
 */
17
class DbService implements ServiceInterface
18
{
19
20
    /**
21
     * @var EntityManager
22
     */
23
    protected $entityManager;
24
25
    /**
26
     * ORM constructor.
27
     *
28
     * @param EntityManager $entityManager
29
     *
30
     * @codeCoverageIgnore
31
     */
32
    public function __construct(EntityManager $entityManager)
33
    {
34
        $this->entityManager = $entityManager;
35
    }
36
37
    /**
38
     * @return EntityManager
39
     */
40
    public function getManager()
41
    {
42
        return $this->entityManager;
43
    }
44
45
    /**
46
     * Return the EntityFetcher
47
     *
48
     * @param string       $entity
49
     * @param integer|null $primaryKey
50
     *
51
     * @return Entity|EntityFetcher
52
     *
53
     * @throws DbException
54
     *
55
     * @codeCoverageIgnore Is covered by tflori/orm
56
     */
57
    public function fetch(string $entity, $primaryKey = null)
58
    {
59
        try {
60
            return $this->entityManager->fetch($entity, $primaryKey);
61
        } catch (\Exception $e) {
62
            throw new DbException($e->getMessage(), $e->getCode(), $e->getFile());
63
        }
64
    }
65
66
}