MigrationPlanList::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Metadata;
6
7
use Countable;
8
use Doctrine\Migrations\Exception\NoMigrationsFoundWithCriteria;
9
use function count;
10
use function end;
11
use function reset;
12
13
/**
14
 * Represents a sorted list of MigrationPlan instances to execute.
15
 */
16
final class MigrationPlanList implements Countable
17
{
18
    /** @var string */
19
    private $direction;
20
21
    /** @var MigrationPlan[] */
22
    private $items = [];
23
24
    /**
25
     * @param MigrationPlan[] $items
26
     */
27 53
    public function __construct(array $items, string $direction)
28
    {
29 53
        $this->items     = $items;
30 53
        $this->direction = $direction;
31 53
    }
32
33 31
    public function count() : int
34
    {
35 31
        return count($this->items);
36
    }
37
38
    /**
39
     * @return MigrationPlan[]
40
     */
41 11
    public function getItems() : array
42
    {
43 11
        return $this->items;
44
    }
45
46 30
    public function getDirection() : string
47
    {
48 30
        return $this->direction;
49
    }
50
51 8
    public function getFirst() : MigrationPlan
52
    {
53 8
        if (count($this->items) === 0) {
54 1
            throw NoMigrationsFoundWithCriteria::new('first');
55
        }
56
57 7
        return reset($this->items);
58
    }
59
60 4
    public function getLast() : MigrationPlan
61
    {
62 4
        if (count($this->items) === 0) {
63 1
            throw NoMigrationsFoundWithCriteria::new('last');
64
        }
65
66 3
        return end($this->items);
67
    }
68
}
69