Completed
Branch feature/pre-split (67216b)
by Anton
03:28
created

State::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 4
rs 9.4285
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Migrations\Migration;
9
10
/**
11
 * Migration meta information specific to current environment
12
 */
13
final class State
14
{
15
    /**
16
     * Migration statues.
17
     */
18
    const STATUS_UNDEFINED = -1;
19
    const STATUS_PENDING   = 0;
20
    const STATUS_EXECUTED  = 1;
21
22
    /**
23
     * @var string
24
     */
25
    private $name = '';
26
27
    /**
28
     * @var bool
29
     */
30
    private $status = self::STATUS_PENDING;
31
32
    /**
33
     * @var \DateTime
34
     */
35
    private $timeCreated = null;
36
37
    /**
38
     * @var \DateTime|null
39
     */
40
    private $timeExecuted = null;
41
42
    /**
43
     * @param string    $name
44
     * @param \DateTime $timeCreated
45
     * @param int       $status
46
     * @param \DateTime $timeExecuted
47
     */
48
    public function __construct(
49
        string $name,
50
        \DateTime $timeCreated,
51
        int $status = self::STATUS_UNDEFINED,
52
        \DateTime $timeExecuted = null
53
    ) {
54
        $this->name = $name;
55
        $this->status = $status;
0 ignored issues
show
Documentation Bug introduced by
The property $status was declared of type boolean, but $status is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
56
        $this->timeCreated = $timeCreated;
57
        $this->timeExecuted = $timeExecuted;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getName(): string
64
    {
65
        return $this->name;
66
    }
67
68
    /**
69
     * Migration status.
70
     *
71
     * @return int
72
     */
73
    public function getStatus(): int
74
    {
75
        return $this->status;
76
    }
77
78
    /**
79
     * Get migration creation time.
80
     *
81
     * @return \DateTime
82
     */
83
    public function getTimeCreated(): \DateTime
84
    {
85
        return $this->timeCreated;
86
    }
87
88
    /**
89
     * Get migration execution time if any.
90
     *
91
     * @return \DateTime|null
92
     */
93
    public function getTimeExecuted()
94
    {
95
        return $this->timeExecuted;
96
    }
97
98
    /**
99
     * @param int            $status
100
     * @param \DateTime|null $timeExecuted
101
     *
102
     * @return State
103
     */
104
    public function withStatus(int $status, \DateTime $timeExecuted = null): State
105
    {
106
        $state = clone $this;
107
        $state->status = $status;
0 ignored issues
show
Documentation Bug introduced by
The property $status was declared of type boolean, but $status is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
108
        $state->timeExecuted = $timeExecuted;
109
110
        return $state;
111
    }
112
}