Passed
Push — master ( 229462...d74785 )
by Andreas
02:20 queued 14s
created

ConcatenationFileBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 4

1 Method

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