AvailableMigrationsSet   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 48
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getItems() 0 4 1
A count() 0 4 1
A hasMigration() 0 10 3
A getMigration() 0 10 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Metadata;
6
7
use Countable;
8
use Doctrine\Migrations\Exception\MigrationNotAvailable;
9
use Doctrine\Migrations\Version\Version;
10
use function array_values;
11
use function count;
12
13
/**
14
 * Represents a non sorted list of migrations that may or may not be already executed.
15
 */
16
final class AvailableMigrationsSet implements Countable
17
{
18
    /** @var AvailableMigration[] */
19
    private $items = [];
20
21
    /**
22
     * @param AvailableMigration[] $items
23
     */
24 86
    public function __construct(array $items)
25
    {
26 86
        $this->items = array_values($items);
27 86
    }
28
29
    /**
30
     * @return AvailableMigration[]
31
     */
32 79
    public function getItems() : array
33
    {
34 79
        return $this->items;
35
    }
36
37 7
    public function count() : int
38
    {
39 7
        return count($this->items);
40
    }
41
42 1
    public function hasMigration(Version $version) : bool
43
    {
44 1
        foreach ($this->items as $migration) {
45 1
            if ($migration->getVersion()->equals($version)) {
46 1
                return true;
47
            }
48
        }
49
50 1
        return false;
51
    }
52
53 1
    public function getMigration(Version $version) : AvailableMigration
54
    {
55 1
        foreach ($this->items as $migration) {
56 1
            if ($migration->getVersion()->equals($version)) {
57 1
                return $migration;
58
            }
59
        }
60
61
        throw MigrationNotAvailable::forVersion($version);
62
    }
63
}
64