Failed Conditions
Push — master ( 4bfa22...148895 )
by Guilherme
17:21 queued 09:56
created

ManyToOneAssociationMetadataBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 40
ccs 20
cts 20
cp 1
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 25 2
A withManyToOneAnnotation() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Mapping\Builder;
6
7
use Doctrine\ORM\Annotation;
8
use Doctrine\ORM\Mapping;
9
use function assert;
10
11
class ManyToOneAssociationMetadataBuilder extends ToOneAssociationMetadataBuilder
12
{
13
    /** @var Annotation\ManyToOne */
14
    private $manyToOneAnnotation;
15
16 149
    public function withManyToOneAnnotation(Annotation\ManyToOne $manyToOneAnnotation) : ManyToOneAssociationMetadataBuilder
17
    {
18 149
        $this->manyToOneAnnotation = $manyToOneAnnotation;
19
20 149
        return $this;
21
    }
22
23
    /**
24
     * @internal Association metadata order of definition settings is important.
25
     */
26 149
    public function build() : Mapping\ManyToOneAssociationMetadata
27
    {
28
        // Validate required fields
29 149
        assert($this->componentMetadata !== null);
30 149
        assert($this->manyToOneAnnotation !== null);
31 149
        assert($this->fieldName !== null);
32
33 149
        $componentClassName  = $this->componentMetadata->getClassName();
34 149
        $associationMetadata = new Mapping\ManyToOneAssociationMetadata($this->fieldName);
35
36 149
        $associationMetadata->setSourceEntity($componentClassName);
37 149
        $associationMetadata->setTargetEntity($this->getTargetEntity($this->manyToOneAnnotation->targetEntity));
38 149
        $associationMetadata->setCascade($this->getCascade($this->manyToOneAnnotation->cascade));
39 149
        $associationMetadata->setFetchMode($this->getFetchMode($this->manyToOneAnnotation->fetch));
40 149
        $associationMetadata->setOwningSide(true);
41
42 149
        if (! empty($this->manyToOneAnnotation->inversedBy)) {
43 96
            $associationMetadata->setInversedBy($this->manyToOneAnnotation->inversedBy);
44
        }
45
46 149
        $this->buildCache($associationMetadata);
47 149
        $this->buildPrimaryKey($associationMetadata);
48 147
        $this->buildJoinColumns($associationMetadata);
49
50 147
        return $associationMetadata;
51
    }
52
}
53