Rollup   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 39
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A rollup() 0 19 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations;
6
7
use Doctrine\Migrations\Exception\RollupFailed;
8
use Doctrine\Migrations\Metadata\Storage\MetadataStorage;
9
use Doctrine\Migrations\Version\ExecutionResult;
10
use Doctrine\Migrations\Version\Version;
11
use function count;
12
13
/**
14
 * The Rollup class is responsible for deleting all previously executed migrations from the versions table
15
 * and marking the freshly dumped schema migration (that was created with SchemaDumper) as migrated.
16
 *
17
 * @internal
18
 */
19
class Rollup
20
{
21
    /** @var MigrationsRepository */
22
    private $migrationRepository;
23
24
    /** @var MetadataStorage */
25
    private $metadataStorage;
26
27 3
    public function __construct(
28
        MetadataStorage $metadataStorage,
29
        MigrationsRepository $migrationRepository
30
    ) {
31 3
        $this->migrationRepository = $migrationRepository;
32 3
        $this->metadataStorage     = $metadataStorage;
33 3
    }
34
35
    /**
36
     * @throws RollupFailed
37
     */
38 3
    public function rollup() : Version
39
    {
40 3
        $versions = $this->migrationRepository->getMigrations();
41
42 3
        if (count($versions) === 0) {
43 1
            throw RollupFailed::noMigrationsFound();
44
        }
45
46 2
        if (count($versions) > 1) {
47 1
            throw RollupFailed::tooManyMigrations();
48
        }
49
50 1
        $this->metadataStorage->reset();
51
52 1
        $result = new ExecutionResult($versions->getItems()[0]->getVersion());
53 1
        $this->metadataStorage->complete($result);
54
55 1
        return $result->getVersion();
56
    }
57
}
58