GenericRepository::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 0
loc 9
ccs 7
cts 7
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Igni\Storage\Driver;
4
5
use Igni\Storage\EntityManager;
6
use Igni\Storage\Hydration\ObjectHydrator;
7
use Igni\Storage\Mapping\MetaData\EntityMetaData;
8
use Igni\Storage\Repository;
9
10
abstract class GenericRepository implements Repository
11
{
12
    /**
13
     * @var Connection
14
     */
15
    protected $connection;
16
    /**
17
     * @var EntityManager
18
     */
19
    protected $entityManager;
20
    /**
21
     * @var ObjectHydrator
22
     */
23
    protected $hydrator;
24
25
    /**
26
     * @var EntityMetaData
27
     */
28
    protected $metaData;
29
30 22
    public function __construct(EntityManager $entityManager, Connection $connection = null)
31
    {
32 22
        $this->entityManager = $entityManager;
33 22
        $this->metaData = $this->entityManager->getMetaData($this->getEntityClass());
34 22
        $this->hydrator = $this->entityManager->getHydrator($this->getEntityClass());
35 22
        if ($connection === null) {
36 22
            $connection = ConnectionManager::get($this->metaData->getConnection());
37
        }
38 22
        $this->connection = $connection;
39 22
    }
40
}
41