Failed Conditions
Pull Request — master (#10)
by Adrien
02:42
created

AbstractFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Doctrine\Factory;
6
7
use Doctrine\Common\Annotations\Reader;
8
use Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver;
9
use Doctrine\ORM\EntityManager;
10
use GraphQL\Doctrine\Exception;
11
use GraphQL\Doctrine\Types;
12
13
/**
14
 * Abstract factory to be aware of types and entityManager
15
 */
16
abstract class AbstractFactory
17
{
18
    /**
19
     * @var Types
20
     */
21
    protected $types;
22
23
    /**
24
     * @var EntityManager
25
     */
26
    protected $entityManager;
27
28 62
    public function __construct(Types $types, EntityManager $entityManager)
29
    {
30 62
        $this->types = $types;
31 62
        $this->entityManager = $entityManager;
32 62
    }
33
34
    /**
35
     * Get annotation reader
36
     *
37
     * @return Reader
38
     */
39 28
    final protected function getAnnotationReader(): Reader
40
    {
41 28
        $driver = $this->entityManager->getConfiguration()->getMetadataDriverImpl();
42 28
        if (!$driver instanceof AnnotationDriver) {
43 1
            throw new Exception('graphql-doctrine requires Doctrine to be configured with a `' . AnnotationDriver::class . '`.');
44
        }
45
46 27
        return $driver->getReader();
47
    }
48
}
49