|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Conversio\Mail\Pipeline; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class ProcessResult |
|
9
|
|
|
* @package Conversio\Mail\Pipeline |
|
10
|
|
|
*/ |
|
11
|
|
|
final class ProcessResult |
|
12
|
|
|
{ |
|
13
|
|
|
const SUCCEEDED = 'success'; |
|
14
|
|
|
const FAILED = 'failed'; |
|
15
|
|
|
const ERRORED = 'errored'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
private $status; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
private $infos = []; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
private $attributes = []; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @return ProcessResult |
|
|
|
|
|
|
34
|
|
|
*/ |
|
35
|
6 |
|
public static function new(): self |
|
36
|
|
|
{ |
|
37
|
6 |
|
return new self(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param string $status |
|
42
|
|
|
* |
|
43
|
|
|
* @return $this |
|
44
|
|
|
*/ |
|
45
|
4 |
|
public function setStatus(string $status) |
|
46
|
|
|
{ |
|
47
|
4 |
|
$this->status = $status; |
|
48
|
|
|
|
|
49
|
4 |
|
return $this; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return bool |
|
54
|
|
|
*/ |
|
55
|
3 |
|
public function succeeded(): bool |
|
56
|
|
|
{ |
|
57
|
3 |
|
return $this->status === self::SUCCEEDED; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return bool |
|
62
|
|
|
*/ |
|
63
|
4 |
|
public function failed(): bool |
|
64
|
|
|
{ |
|
65
|
4 |
|
return $this->status === self::FAILED; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return bool |
|
70
|
|
|
*/ |
|
71
|
3 |
|
public function errored(): bool |
|
72
|
|
|
{ |
|
73
|
3 |
|
return $this->status === self::ERRORED; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param string $key |
|
78
|
|
|
* @param string $info |
|
79
|
|
|
*/ |
|
80
|
2 |
|
public function addInfo(string $key, string $info) |
|
81
|
|
|
{ |
|
82
|
2 |
|
$this->infos[$key] = $info; |
|
83
|
2 |
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param string $key |
|
87
|
|
|
* |
|
88
|
|
|
* @return bool |
|
89
|
|
|
*/ |
|
90
|
2 |
|
public function hasInfoFor(string $key): bool |
|
91
|
|
|
{ |
|
92
|
2 |
|
return array_key_exists($key, $this->infos); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @param string $key |
|
97
|
|
|
* |
|
98
|
|
|
* @return string |
|
99
|
|
|
* @throws Exception |
|
100
|
|
|
*/ |
|
101
|
2 |
|
public function getInfo(string $key): string |
|
102
|
|
|
{ |
|
103
|
2 |
|
if ($this->hasInfoFor($key)) { |
|
104
|
2 |
|
return $this->infos[$key]; |
|
105
|
|
|
} |
|
106
|
|
|
throw new Exception(sprintf('no information available for %s', $key)); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param $key |
|
111
|
|
|
* |
|
112
|
|
|
* @return bool |
|
113
|
|
|
*/ |
|
114
|
2 |
|
public function hasAttribute($key): bool |
|
115
|
|
|
{ |
|
116
|
2 |
|
return array_key_exists($key, $this->attributes); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param $key |
|
121
|
|
|
* |
|
122
|
|
|
* @return mixed |
|
123
|
|
|
* @throws Exception |
|
124
|
|
|
*/ |
|
125
|
1 |
|
public function getAttribute($key) |
|
126
|
|
|
{ |
|
127
|
1 |
|
if ($this->hasAttribute($key)) { |
|
128
|
|
|
return $this->attributes[$key]; |
|
129
|
|
|
} |
|
130
|
1 |
|
throw new Exception(sprintf('no attribute set fpr %s', $key)); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @param $key |
|
135
|
|
|
* @param $value |
|
136
|
|
|
* |
|
137
|
|
|
* @return self |
|
138
|
|
|
*/ |
|
139
|
1 |
|
public function withAttribute($key, $value): self |
|
140
|
|
|
{ |
|
141
|
1 |
|
$this->attributes[$key] = $value; |
|
142
|
|
|
|
|
143
|
1 |
|
return $this; |
|
144
|
|
|
} |
|
145
|
|
|
} |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.