Passed
Pull Request — master (#969)
by Asmir
02:34
created

AvailableMigrationsSet::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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
 * 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 76
    public function __construct(array $items)
25
    {
26 76
        $this->items = array_values($items);
27 76
    }
28
29
    /**
30
     * @return AvailableMigration[]
31
     */
32 69
    public function getItems() : array
33
    {
34 69
        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