Completed
Push — master ( ca826f...dcd1d0 )
by Asmir
18s queued 15s
created

ExecutionResult::setTime()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Version;
6
7
use DateTimeImmutable;
8
use Doctrine\DBAL\Schema\Schema;
9
use Doctrine\Migrations\Query\Query;
10
use RuntimeException;
11
use Throwable;
12
use function count;
13
14
/**
15
 * The ExecutionResult class is responsible for storing the result of a migration version after it executes.
16
 *
17
 * @internal
18
 */
19
final class ExecutionResult
20
{
21
    /** @var Query[] */
22
    private $sql = [];
23
24
    /** @var float|null */
25
    private $time;
26
27
    /** @var float|null */
28
    private $memory;
29
30
    /** @var bool */
31
    private $skipped = false;
32
33
    /** @var bool */
34
    private $error = false;
35
36
    /** @var Throwable|null */
37
    private $exception;
38
39
    /** @var DateTimeImmutable|null */
40
    private $executedAt;
41
42
    /** @var int */
43
    private $state;
44
45
    /** @var Schema|null */
46
    private $toSchema;
47
48
    /** @var Version */
49
    private $version;
50
51
    /** @var string */
52
    private $direction;
53
54 65
    public function __construct(Version $version, string $direction = Direction::UP, ?DateTimeImmutable $executedAt = null)
55
    {
56 65
        $this->executedAt = $executedAt;
57 65
        $this->version    = $version;
58 65
        $this->direction  = $direction;
59 65
    }
60
61 38
    public function getDirection() : string
62
    {
63 38
        return $this->direction;
64
    }
65
66 39
    public function getExecutedAt() : ?DateTimeImmutable
67
    {
68 39
        return $this->executedAt;
69
    }
70
71 1
    public function setExecutedAt(DateTimeImmutable $executedAt) : void
72
    {
73 1
        $this->executedAt = $executedAt;
74 1
    }
75
76 38
    public function getVersion() : Version
77
    {
78 38
        return $this->version;
79
    }
80
81 1
    public function hasSql() : bool
82
    {
83 1
        return count($this->sql) !== 0;
84
    }
85
86
    /**
87
     * @return Query[]
88
     */
89 10
    public function getSql() : array
90
    {
91 10
        return $this->sql;
92
    }
93
94
    /**
95
     * @param Query[] $sql
96
     */
97 22
    public function setSql(array $sql) : void
98
    {
99 22
        $this->sql = $sql;
100 22
    }
101
102 43
    public function getTime() : ?float
103
    {
104 43
        return $this->time;
105
    }
106
107 20
    public function setTime(float $time) : void
108
    {
109 20
        $this->time = $time;
110 20
    }
111
112 1
    public function getMemory() : ?float
113
    {
114 1
        return $this->memory;
115
    }
116
117 12
    public function setMemory(float $memory) : void
118
    {
119 12
        $this->memory = $memory;
120 12
    }
121
122 2
    public function setSkipped(bool $skipped) : void
123
    {
124 2
        $this->skipped = $skipped;
125 2
    }
126
127 7
    public function isSkipped() : bool
128
    {
129 7
        return $this->skipped;
130
    }
131
132 5
    public function setError(bool $error, ?Throwable $exception = null) : void
133
    {
134 5
        $this->error     = $error;
135 5
        $this->exception = $exception;
136 5
    }
137
138 4
    public function hasError() : bool
139
    {
140 4
        return $this->error;
141
    }
142
143 2
    public function getException() : ?Throwable
144
    {
145 2
        return $this->exception;
146
    }
147
148 15
    public function setToSchema(Schema $toSchema) : void
149
    {
150 15
        $this->toSchema = $toSchema;
151 15
    }
152
153 4
    public function getToSchema() : Schema
154
    {
155 4
        if ($this->toSchema === null) {
156 1
            throw new RuntimeException('Cannot call getToSchema() when toSchema is null.');
157
        }
158
159 3
        return $this->toSchema;
160
    }
161
162 8
    public function getState() : int
163
    {
164 8
        return $this->state;
165
    }
166
167 14
    public function setState(int $state) : void
168
    {
169 14
        $this->state = $state;
170 14
    }
171
}
172