Failed Conditions
Push — master ( becf73...b9880b )
by Guilherme
09:53
created

FieldMetadataExporter::export()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 12
ccs 0
cts 9
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Mapping\Exporter;
6
7
use Doctrine\ORM\Mapping\ColumnMetadata;
8
use Doctrine\ORM\Mapping\FieldMetadata;
9
use const PHP_EOL;
10
use function assert;
11
use function implode;
12
use function ltrim;
13
use function sprintf;
14
use function str_repeat;
15
16
class FieldMetadataExporter extends LocalColumnMetadataExporter
17
{
18
    public const VARIABLE = '$property';
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function export($value, int $indentationLevel = 0) : string
24
    {
25
        /** @var FieldMetadata $value */
26
        $variableExporter = new VariableExporter();
27
        $indentation      = str_repeat(self::INDENTATION, $indentationLevel);
28
        $objectReference  = $indentation . self::VARIABLE;
29
30
        $lines   = [];
31
        $lines[] = parent::export($value, $indentationLevel);
32
        $lines[] = $objectReference . '->setVersioned(' . ltrim($variableExporter->export($value->isVersioned(), $indentationLevel + 1)) . ');';
33
34
        return implode(PHP_EOL, $lines);
35
    }
36
37
    protected function exportInstantiation(ColumnMetadata $metadata) : string
38
    {
39
        assert($metadata instanceof FieldMetadata);
40
41
        $lines   = [];
42
        $lines[] = sprintf(
43
            'new Mapping\FieldMetadata("%s", "%s", Type::getType("%s"));',
44
            $metadata->getName(),
45
            $metadata->getColumnName(),
46
            $metadata->getTypeName()
47
        );
48
49
        return implode(PHP_EOL, $lines);
50
    }
51
}
52