ConcatenationFileBuilder::buildMigrationFile()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 8
cts 8
cp 1
rs 9.6666
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Generator;
6
7
use DateTimeImmutable;
8
use DateTimeInterface;
9
use Doctrine\Migrations\Query\Query;
10
use function sprintf;
11
12
/**
13
 * The ConcatenationFileBuilder class is responsible for building a migration SQL file from an array of queries per version.
14
 *
15
 * @internal
16
 */
17
final class ConcatenationFileBuilder implements FileBuilder
18
{
19
    /** @param array<string,Query[]> $queriesByVersion */
20 1
    public function buildMigrationFile(
21
        array $queriesByVersion,
22
        string $direction,
23
        ?DateTimeInterface $now = null
24
    ) : string {
25 1
        $now    = $now ?? new DateTimeImmutable();
26 1
        $string = sprintf("-- Doctrine Migration File Generated on %s\n", $now->format('Y-m-d H:i:s'));
27
28 1
        foreach ($queriesByVersion as $version => $queries) {
29 1
            $string .= "\n-- Version " . $version . "\n";
30
31 1
            foreach ($queries as $query) {
32 1
                $string .= $query->getStatement() . ";\n";
33
            }
34
        }
35
36 1
        return $string;
37
    }
38
}
39