CacheMetadataExporter::exportInstantiation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 6
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\CacheMetadata;
8
use const PHP_EOL;
9
use function implode;
10
use function sprintf;
11
use function str_repeat;
12
use function strtoupper;
13
14
class CacheMetadataExporter implements Exporter
15
{
16
    public const VARIABLE = '$cache';
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function export($value, int $indentationLevel = 0) : string
22
    {
23
        /** @var CacheMetadata $value */
24
        $indentation     = str_repeat(self::INDENTATION, $indentationLevel);
25
        $objectReference = $indentation . self::VARIABLE;
26
        $lines           = [];
27
28
        $lines[] = $objectReference . ' = ' . $this->exportInstantiation($value);
29
30
        return implode(PHP_EOL, $lines);
31
    }
32
33
    protected function exportInstantiation(CacheMetadata $metadata) : string
34
    {
35
        return sprintf(
36
            'new Mapping\CacheMetadata(Mapping\CacheUsage::%s, "%s");',
37
            strtoupper($metadata->getUsage()),
38
            $metadata->getRegion()
39
        );
40
    }
41
}
42