Failed Conditions
Push — master ( c35142...f185a6 )
by Guilherme
08:59
created

TransientMetadataBuilder::withFieldName()   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\Mapping;
8
use function assert;
9
10
class TransientMetadataBuilder
11
{
12
    /** @var Mapping\ClassMetadataBuildingContext */
13
    private $metadataBuildingContext;
14
15
    /** @var Mapping\ClassMetadata */
16
    private $componentMetadata;
17
18
    /** @var string */
19
    private $fieldName;
20
21 29
    public function __construct(Mapping\ClassMetadataBuildingContext $metadataBuildingContext)
22
    {
23 29
        $this->metadataBuildingContext = $metadataBuildingContext;
24 29
    }
25
26 29
    public function withComponentMetadata(Mapping\ClassMetadata $componentMetadata) : TransientMetadataBuilder
27
    {
28 29
        $this->componentMetadata = $componentMetadata;
29
30 29
        return $this;
31
    }
32
33 29
    public function withFieldName(string $fieldName) : TransientMetadataBuilder
34
    {
35 29
        $this->fieldName = $fieldName;
36
37 29
        return $this;
38
    }
39
40 29
    public function build() : Mapping\TransientMetadata
41
    {
42
        // Validate required fields
43 29
        assert($this->componentMetadata !== null);
44 29
        assert($this->fieldName !== null);
45
46 29
        $transientMetadata = new Mapping\TransientMetadata($this->fieldName);
47
48 29
        $transientMetadata->setDeclaringClass($this->componentMetadata);
49
50 29
        return $transientMetadata;
51
    }
52
}