MigrationPlanList   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 53
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A count() 0 4 1
A getItems() 0 4 1
A getDirection() 0 4 1
A getFirst() 0 8 2
A getLast() 0 8 2
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