Completed
Push — master ( 5ff3e1...46578f )
by Jonathan
12s
created

Rollup::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations;
6
7
use Doctrine\DBAL\Connection;
8
use Doctrine\Migrations\Configuration\Configuration;
9
use RuntimeException;
10
use function count;
11
use function current;
12
use function sprintf;
13
14
class Rollup
15
{
16
    /** @var Configuration */
17
    private $configuration;
18
19
    /** @var Connection */
20
    private $connection;
21
22
    /** @var MigrationRepository */
23
    private $migrationRepository;
24
25 4
    public function __construct(
26
        Configuration $configuration,
27
        Connection $connection,
28
        MigrationRepository $migrationRepository
29
    ) {
30 4
        $this->configuration       = $configuration;
31 4
        $this->connection          = $connection;
32 4
        $this->migrationRepository = $migrationRepository;
33 4
    }
34
35 4
    public function rollup() : Version
36
    {
37 4
        $versions = $this->migrationRepository->getVersions();
38
39 4
        if (count($versions) === 0) {
40 1
            throw new RuntimeException('No migrations found.');
41
        }
42
43 3
        if (count($versions) > 1) {
44 1
            throw new RuntimeException('Too many migrations.');
45
        }
46
47 2
        $sql = sprintf(
48 2
            'DELETE FROM %s',
49 2
            $this->configuration->getMigrationsTableName()
50
        );
51
52 2
        $this->connection->executeQuery($sql);
53
54 2
        $version = current($versions);
55
56 2
        $version->markMigrated();
57
58 2
        return $version;
59
    }
60
}
61