|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zenstruck\ScheduleBundle\Schedule\Task; |
|
4
|
|
|
|
|
5
|
|
|
use Zenstruck\ScheduleBundle\Schedule\Task; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @author Kevin Bond <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
final class Result |
|
11
|
|
|
{ |
|
12
|
|
|
public const SUCCESSFUL = 'successful'; |
|
13
|
|
|
public const FAILED = 'failed'; |
|
14
|
|
|
public const SKIPPED = 'skipped'; |
|
15
|
|
|
|
|
16
|
|
|
/** @var Task */ |
|
17
|
|
|
private $task; |
|
18
|
|
|
|
|
19
|
|
|
/** @var string */ |
|
20
|
|
|
private $type; |
|
21
|
|
|
|
|
22
|
87 |
|
/** @var string */ |
|
23
|
|
|
private $description; |
|
24
|
87 |
|
|
|
25
|
87 |
|
/** @var string|null */ |
|
26
|
87 |
|
private $output; |
|
27
|
87 |
|
|
|
28
|
|
|
/** @var \Throwable|null */ |
|
29
|
14 |
|
private $exception; |
|
30
|
|
|
|
|
31
|
14 |
|
private function __construct(Task $task, string $type, string $description) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->task = $task; |
|
34
|
53 |
|
$this->type = $type; |
|
35
|
|
|
$this->description = $description; |
|
36
|
53 |
|
} |
|
37
|
53 |
|
|
|
38
|
|
|
public function __toString(): string |
|
39
|
53 |
|
{ |
|
40
|
|
|
return $this->getDescription(); |
|
41
|
|
|
} |
|
42
|
33 |
|
|
|
43
|
|
|
public static function successful(Task $task, ?string $output = null, string $description = 'Successful'): self |
|
44
|
33 |
|
{ |
|
45
|
33 |
|
$result = new self($task, self::SUCCESSFUL, $description); |
|
46
|
|
|
$result->output = $output; |
|
47
|
33 |
|
|
|
48
|
|
|
return $result; |
|
49
|
|
|
} |
|
50
|
21 |
|
|
|
51
|
|
|
public static function failure(Task $task, string $description, ?string $output = null): self |
|
52
|
21 |
|
{ |
|
53
|
|
|
$result = new self($task, self::FAILED, $description); |
|
54
|
21 |
|
$result->output = $output; |
|
55
|
21 |
|
|
|
56
|
|
|
return $result; |
|
57
|
21 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
public static function exception(Task $task, \Throwable $exception, ?string $output = null, ?string $description = null): self |
|
60
|
15 |
|
{ |
|
61
|
|
|
$description = $description ?: \sprintf('%s: %s', (new \ReflectionClass($exception))->getShortName(), $exception->getMessage()); |
|
62
|
15 |
|
|
|
63
|
|
|
$result = self::failure($task, $description, $output); |
|
64
|
|
|
$result->exception = $exception; |
|
65
|
70 |
|
|
|
66
|
|
|
return $result; |
|
67
|
70 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
public static function skipped(Task $task, string $description): self |
|
70
|
81 |
|
{ |
|
71
|
|
|
return new self($task, self::SKIPPED, $description); |
|
72
|
81 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getTask(): Task |
|
75
|
42 |
|
{ |
|
76
|
|
|
return $this->task; |
|
77
|
42 |
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getType(): string |
|
80
|
38 |
|
{ |
|
81
|
|
|
return $this->type; |
|
82
|
38 |
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getDescription(): string |
|
85
|
13 |
|
{ |
|
86
|
|
|
return $this->description; |
|
87
|
13 |
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getOutput(): ?string |
|
90
|
77 |
|
{ |
|
91
|
|
|
return $this->output; |
|
92
|
77 |
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getException(): ?\Throwable |
|
95
|
70 |
|
{ |
|
96
|
|
|
return $this->exception; |
|
97
|
70 |
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function isSuccessful(): bool |
|
100
|
25 |
|
{ |
|
101
|
|
|
return self::SUCCESSFUL === $this->getType(); |
|
102
|
25 |
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function isFailure(): bool |
|
105
|
38 |
|
{ |
|
106
|
|
|
return self::FAILED === $this->getType(); |
|
107
|
38 |
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function isException(): bool |
|
110
|
37 |
|
{ |
|
111
|
|
|
return $this->isFailure() && $this->exception instanceof \Throwable; |
|
112
|
37 |
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function isSkipped(): bool |
|
115
|
|
|
{ |
|
116
|
|
|
return self::SKIPPED === $this->getType(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function hasRun(): bool |
|
120
|
|
|
{ |
|
121
|
|
|
return self::SKIPPED !== $this->getType(); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|