Failed Conditions
Push — master ( ddb3cd...4476ec )
by Marco
11:47
created

EntityClassMetadataBinder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 68
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A bind() 0 7 1
A processEntityAnnotation() 0 16 3
A __construct() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Mapping\Driver\Annotation\Binder;
6
7
use Doctrine\ORM\Annotation;
8
use Doctrine\ORM\Mapping;
9
10
/**
11
 * Class ComponentMetadataBinder
12
 */
13
class EntityClassMetadataBinder
14
{
15
    /**
16
     * @var Mapping\ClassMetadataBuildingContext
17
     */
18
    private $metadataBuildingContext;
19
20
    /**
21
     * @var \ReflectionClass
22
     */
23
    private $reflectionClass;
24
25
    /**
26
     * [dreaming] One day we would eliminate this and only do: $reflectionClass->getAnnotations()
27
     *
28
     * @var Annotation\Annotation[]
29
     */
30
    private $classAnnotations;
31
32
    /**
33
     * @todo guilhermeblanco This should disappear once we instantiation happens in the Driver
34
     *
35
     * @var Mapping\ClassMetadata
36
     */
37
    private $classMetadata;
38
39
    /**
40
     * ComponentMetadataBinder constructor.
41
     *
42
     * @param Annotation\Annotation[] $classAnnotations
43
     */
44
    public function __construct(
45
        \ReflectionClass $reflectionClass,
46
        array $classAnnotations,
47
        Mapping\ClassMetadata $classMetadata,
48
        Mapping\ClassMetadataBuildingContext $metadataBuildingContext
49
    ) {
50
        $this->reflectionClass         = $reflectionClass;
51
        $this->classAnnotations        = $classAnnotations;
52
        $this->classMetadata           = $classMetadata;
53
        $this->metadataBuildingContext = $metadataBuildingContext;
54
    }
55
56
    public function bind() : Mapping\ClassMetadata
57
    {
58
        $classMetadata = $this->classMetadata;
59
60
        $this->processEntityAnnotation($classMetadata, $this->classAnnotations[Annotation\Entity::class]);
61
62
        return $classMetadata;
63
    }
64
65
    private function processEntityAnnotation(
66
        Mapping\ClassMetadata $classMetadata,
67
        Annotation\Entity $entityAnnotation
68
    ) : void {
69
        if ($entityAnnotation->repositoryClass !== null) {
0 ignored issues
show
introduced by
The condition $entityAnnotation->repositoryClass !== null can never be false.
Loading history...
70
            $repositoryClassName = $entityAnnotation->repositoryClass;
71
72
            $classMetadata->setCustomRepositoryClassName($repositoryClassName);
73
        }
74
75
        if ($entityAnnotation->readOnly) {
76
            $classMetadata->asReadOnly();
77
        }
78
79
        $classMetadata->isMappedSuperclass = false;
80
        $classMetadata->isEmbeddedClass    = false;
81
    }
82
}
83