Failed Conditions
Pull Request — master (#969)
by
unknown
09:23
created

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