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

AvailableMigrationsSet::getMigration()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 9
ccs 4
cts 5
cp 0.8
crap 3.072
rs 10
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