ExecutionResult   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 22
lcom 3
cbo 0
dl 0
loc 157
ccs 56
cts 56
cp 1
rs 10
c 0
b 0
f 0

21 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getDirection() 0 4 1
A getExecutedAt() 0 4 1
A setExecutedAt() 0 4 1
A getVersion() 0 4 1
A hasSql() 0 4 1
A getSql() 0 4 1
A setSql() 0 4 1
A getTime() 0 4 1
A setTime() 0 4 1
A getMemory() 0 4 1
A setMemory() 0 4 1
A setSkipped() 0 4 1
A isSkipped() 0 4 1
A setError() 0 5 1
A hasError() 0 4 1
A getException() 0 4 1
A setToSchema() 0 4 1
A getToSchema() 0 8 2
A getState() 0 4 1
A setState() 0 4 1
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
    /**
25
     * Seconds
26
     *
27
     * @var float|null
28
     */
29
    private $time;
30
31
    /** @var float|null */
32
    private $memory;
33
34
    /** @var bool */
35
    private $skipped = false;
36
37
    /** @var bool */
38
    private $error = false;
39
40
    /** @var Throwable|null */
41
    private $exception;
42
43
    /** @var DateTimeImmutable|null */
44
    private $executedAt;
45
46
    /** @var int */
47
    private $state;
48
49
    /** @var Schema|null */
50
    private $toSchema;
51
52
    /** @var Version */
53
    private $version;
54
55
    /** @var string */
56
    private $direction;
57
58 74
    public function __construct(Version $version, string $direction = Direction::UP, ?DateTimeImmutable $executedAt = null)
59
    {
60 74
        $this->executedAt = $executedAt;
61 74
        $this->version    = $version;
62 74
        $this->direction  = $direction;
63 74
    }
64
65 47
    public function getDirection() : string
66
    {
67 47
        return $this->direction;
68
    }
69
70 48
    public function getExecutedAt() : ?DateTimeImmutable
71
    {
72 48
        return $this->executedAt;
73
    }
74
75 1
    public function setExecutedAt(DateTimeImmutable $executedAt) : void
76
    {
77 1
        $this->executedAt = $executedAt;
78 1
    }
79
80 47
    public function getVersion() : Version
81
    {
82 47
        return $this->version;
83
    }
84
85 1
    public function hasSql() : bool
86
    {
87 1
        return count($this->sql) !== 0;
88
    }
89
90
    /**
91
     * @return Query[]
92
     */
93 11
    public function getSql() : array
94
    {
95 11
        return $this->sql;
96
    }
97
98
    /**
99
     * @param Query[] $sql
100
     */
101 23
    public function setSql(array $sql) : void
102
    {
103 23
        $this->sql = $sql;
104 23
    }
105
106 52
    public function getTime() : ?float
107
    {
108 52
        return $this->time;
109
    }
110
111 21
    public function setTime(float $time) : void
112
    {
113 21
        $this->time = $time;
114 21
    }
115
116 1
    public function getMemory() : ?float
117
    {
118 1
        return $this->memory;
119
    }
120
121 13
    public function setMemory(float $memory) : void
122
    {
123 13
        $this->memory = $memory;
124 13
    }
125
126 2
    public function setSkipped(bool $skipped) : void
127
    {
128 2
        $this->skipped = $skipped;
129 2
    }
130
131 8
    public function isSkipped() : bool
132
    {
133 8
        return $this->skipped;
134
    }
135
136 5
    public function setError(bool $error, ?Throwable $exception = null) : void
137
    {
138 5
        $this->error     = $error;
139 5
        $this->exception = $exception;
140 5
    }
141
142 4
    public function hasError() : bool
143
    {
144 4
        return $this->error;
145
    }
146
147 2
    public function getException() : ?Throwable
148
    {
149 2
        return $this->exception;
150
    }
151
152 16
    public function setToSchema(Schema $toSchema) : void
153
    {
154 16
        $this->toSchema = $toSchema;
155 16
    }
156
157 5
    public function getToSchema() : Schema
158
    {
159 5
        if ($this->toSchema === null) {
160 1
            throw new RuntimeException('Cannot call getToSchema() when toSchema is null.');
161
        }
162
163 4
        return $this->toSchema;
164
    }
165
166 8
    public function getState() : int
167
    {
168 8
        return $this->state;
169
    }
170
171 15
    public function setState(int $state) : void
172
    {
173 15
        $this->state = $state;
174 15
    }
175
}
176