ColumnMetadataExporter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 31
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A export() 0 21 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Mapping\Exporter;
6
7
use Doctrine\ORM\Mapping\ColumnMetadata;
8
use const PHP_EOL;
9
use function implode;
10
use function ltrim;
11
use function str_repeat;
12
13
abstract class ColumnMetadataExporter implements Exporter
14
{
15
    public const VARIABLE = '$column';
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function export($value, int $indentationLevel = 0) : string
21
    {
22
        /** @var ColumnMetadata $value */
23
        $variableExporter = new VariableExporter();
24
        $indentation      = str_repeat(self::INDENTATION, $indentationLevel);
25
        $objectReference  = $indentation . self::VARIABLE;
26
        $lines            = [];
27
28
        $lines[] = $objectReference . ' = ' . $this->exportInstantiation($value);
29
30
        if (! empty($value->getColumnDefinition())) {
31
            $lines[] = $objectReference . '->setColumnDefinition("' . $value->getColumnDefinition() . '");';
32
        }
33
34
        $lines[] = $objectReference . '->setTableName("' . $value->getTableName() . '");';
35
        $lines[] = $objectReference . '->setOptions(' . ltrim($variableExporter->export($value->getOptions(), $indentationLevel + 1)) . ');';
36
        $lines[] = $objectReference . '->setPrimaryKey(' . ltrim($variableExporter->export($value->isPrimaryKey(), $indentationLevel + 1)) . ');';
37
        $lines[] = $objectReference . '->setNullable(' . ltrim($variableExporter->export($value->isNullable(), $indentationLevel + 1)) . ');';
38
        $lines[] = $objectReference . '->setUnique(' . ltrim($variableExporter->export($value->isUnique(), $indentationLevel + 1)) . ');';
39
40
        return implode(PHP_EOL, $lines);
41
    }
42
43
    abstract protected function exportInstantiation(ColumnMetadata $metadata) : string;
44
}
45