Completed
Pull Request — master (#969)
by Asmir
02:41
created

AvailableMigrationsSet   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 94.12%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 46
ccs 16
cts 17
cp 0.9412
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getItems() 0 3 1
A getMigration() 0 9 3
A hasMigration() 0 9 3
A count() 0 3 1
A __construct() 0 3 1
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
 * The class AvailableMigrationsSet represents a non sorted set of available migrations.
15
 * The migrations in this set might be already executed or not.
16
 */
17
final class AvailableMigrationsSet implements Countable
18
{
19
    /** @var AvailableMigration[] */
20
    private $items = [];
21
22
    /**
23
     * @param AvailableMigration[] $items
24
     */
25 76
    public function __construct(array $items)
26
    {
27 76
        $this->items = array_values($items);
28 76
    }
29
30
    /**
31
     * @return AvailableMigration[]
32
     */
33 69
    public function getItems() : array
34
    {
35 69
        return $this->items;
36
    }
37
38 7
    public function count() : int
39
    {
40 7
        return count($this->items);
41
    }
42
43 1
    public function hasMigration(Version $version) : bool
44
    {
45 1
        foreach ($this->items as $migration) {
46 1
            if ($migration->getVersion()->equals($version)) {
47 1
                return true;
48
            }
49
        }
50
51 1
        return false;
52
    }
53
54 1
    public function getMigration(Version $version) : AvailableMigration
55
    {
56 1
        foreach ($this->items as $migration) {
57 1
            if ($migration->getVersion()->equals($version)) {
58 1
                return $migration;
59
            }
60
        }
61
62
        throw MigrationNotAvailable::forVersion($version);
63
    }
64
}
65