Failed Conditions
Pull Request — master (#7799)
by Guilherme
09:17
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 array_merge;
0 ignored issues
show
introduced by
Type array_merge is not used in this file.
Loading history...
10
use function array_unique;
0 ignored issues
show
introduced by
Type array_unique is not used in this file.
Loading history...
11
use function assert;
12
13
class ManyToOneAssociationMetadataBuilder extends ToOneAssociationMetadataBuilder
14
{
15
    /** @var Annotation\ManyToOne */
16
    private $manyToOneAnnotation;
17
18 149
    public function withManyToOneAnnotation(Annotation\ManyToOne $manyToOneAnnotation) : ManyToOneAssociationMetadataBuilder
19
    {
20 149
        $this->manyToOneAnnotation = $manyToOneAnnotation;
21
22 149
        return $this;
23
    }
24
25
    /**
26
     * @internal Association metadata order of definition settings is important.
27
     */
28 149
    public function build() : Mapping\ManyToOneAssociationMetadata
29
    {
30
        // Validate required fields
31 149
        assert($this->componentMetadata !== null);
32 149
        assert($this->manyToOneAnnotation !== null);
33 149
        assert($this->fieldName !== null);
34
35 149
        $componentClassName  = $this->componentMetadata->getClassName();
36 149
        $associationMetadata = new Mapping\ManyToOneAssociationMetadata($this->fieldName);
37
38 149
        $associationMetadata->setSourceEntity($componentClassName);
39 149
        $associationMetadata->setTargetEntity($this->getTargetEntity($this->manyToOneAnnotation->targetEntity));
40 149
        $associationMetadata->setCascade($this->getCascade($this->manyToOneAnnotation->cascade));
41 149
        $associationMetadata->setFetchMode($this->getFetchMode($this->manyToOneAnnotation->fetch));
42 149
        $associationMetadata->setOwningSide(true);
43
44 149
        if (! empty($this->manyToOneAnnotation->inversedBy)) {
45 96
            $associationMetadata->setInversedBy($this->manyToOneAnnotation->inversedBy);
46
        }
47
48 149
        $this->buildCache($associationMetadata);
49 149
        $this->buildPrimaryKey($associationMetadata);
50 147
        $this->buildJoinColumns($associationMetadata);
51
52 147
        return $associationMetadata;
53
    }
54
}