Passed
Pull Request — master (#969)
by Asmir
01:58
created

AvailableMigrationsSet::hasMigration()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

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 5
cts 5
cp 1
crap 3
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
final class AvailableMigrationsSet implements Countable
14
{
15
    /** @var AvailableMigration[] */
16
    private $items = [];
17
18
    /**
19
     * @param AvailableMigration[] $items
20
     */
21 76
    public function __construct(array $items)
22
    {
23 76
        $this->items = array_values($items);
24 76
    }
25
26
    /**
27
     * @return AvailableMigration[]
28
     */
29 69
    public function getItems() : array
30
    {
31 69
        return $this->items;
32
    }
33
34 7
    public function count() : int
35
    {
36 7
        return count($this->items);
37
    }
38
39 1
    public function hasMigration(Version $version) : bool
40
    {
41 1
        foreach ($this->items as $migration) {
42 1
            if ($migration->getVersion()->equals($version)) {
43 1
                return true;
44
            }
45
        }
46
47 1
        return false;
48
    }
49
50 1
    public function getMigration(Version $version) : AvailableMigration
51
    {
52 1
        foreach ($this->items as $migration) {
53 1
            if ($migration->getVersion()->equals($version)) {
54 1
                return $migration;
55
            }
56
        }
57
58
        throw MigrationNotAvailable::forVersion($version);
59
    }
60
}
61