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

AbstractFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 31
rs 10
c 0
b 0
f 0
ccs 9
cts 9
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAnnotationReader() 0 8 2
A __construct() 0 4 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