State::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 6
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Migrations;
6
7
use DateTimeInterface;
8
9
/**
10
 * Migration meta information specific to current environment
11
 */
12
final class State
13
{
14
    // Migration status
15
    public const STATUS_UNDEFINED = -1;
16
    public const STATUS_PENDING = 0;
17
    public const STATUS_EXECUTED = 1;
18
19 328
    public function __construct(
20
        private string $name,
21
        private DateTimeInterface $timeCreated,
22
        private int $status = self::STATUS_UNDEFINED,
23
        private ?DateTimeInterface $timeExecuted = null
24
    ) {
25
    }
26
27 304
    public function getName(): string
28
    {
29 304
        return $this->name;
30
    }
31
32 296
    public function getStatus(): int
33
    {
34 296
        return $this->status;
35
    }
36
37 304
    public function getTimeCreated(): DateTimeInterface
38
    {
39 304
        return $this->timeCreated;
40
    }
41
42 8
    public function getTimeExecuted(): ?DateTimeInterface
43
    {
44 8
        return $this->timeExecuted;
45
    }
46
47 296
    public function withStatus(int $status, DateTimeInterface $timeExecuted = null): self
48
    {
49 296
        $state = clone $this;
50 296
        $state->status = $status;
51 296
        $state->timeExecuted = $timeExecuted;
52
53 296
        return $state;
54
    }
55
}
56