Failed Conditions
Pull Request — master (#7799)
by Guilherme
09:17
created

withManyToOneAnnotation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
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
}