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

Rollup   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
B rollup() 0 24 3
A __construct() 0 8 1
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