|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
namespace Webhook\Domain\Infrastructure; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class RequestResult |
|
9
|
|
|
* |
|
10
|
|
|
* @package Webhook\Domain\Infrastructure |
|
11
|
|
|
*/ |
|
12
|
|
|
final class RequestResult |
|
13
|
|
|
{ |
|
14
|
|
|
const SUCCESS = 'success'; |
|
15
|
|
|
const CODE_MISS_MATCH = 'code_miss_match'; |
|
16
|
|
|
const CONTENT_MISS_MATCH = 'content_miss_match'; |
|
17
|
|
|
const TRANSPORT_ERROR = 'transport_error'; |
|
18
|
|
|
|
|
19
|
|
|
/** @var string */ |
|
20
|
|
|
private $status; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string|null */ |
|
23
|
|
|
private $details; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* RequestResult constructor. |
|
27
|
|
|
* |
|
28
|
|
|
* @param string $status |
|
29
|
|
|
* @param string|null $details |
|
30
|
|
|
*/ |
|
31
|
11 |
|
private function __construct(string $status, string $details = null) |
|
32
|
|
|
{ |
|
33
|
11 |
|
$this->status = $status; |
|
34
|
11 |
|
$this->details = $details; |
|
35
|
11 |
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return RequestResult |
|
39
|
|
|
*/ |
|
40
|
11 |
|
public static function success(): RequestResult |
|
41
|
|
|
{ |
|
42
|
11 |
|
return new self(self::SUCCESS); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param $code |
|
47
|
|
|
* |
|
48
|
|
|
* @return RequestResult |
|
49
|
|
|
*/ |
|
50
|
2 |
|
public static function codeMissMatch($code): RequestResult |
|
51
|
|
|
{ |
|
52
|
2 |
|
return new self(self::CODE_MISS_MATCH, (string) $code); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return RequestResult |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public static function contentMissMatch(): RequestResult |
|
59
|
|
|
{ |
|
60
|
1 |
|
return new self(self::CONTENT_MISS_MATCH); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param string $error |
|
65
|
|
|
* |
|
66
|
|
|
* @return RequestResult |
|
67
|
|
|
*/ |
|
68
|
2 |
|
public static function transportError(string $error): RequestResult |
|
69
|
|
|
{ |
|
70
|
2 |
|
return new self(self::TRANSPORT_ERROR, $error); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return bool |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function isTransportError(): bool |
|
77
|
|
|
{ |
|
78
|
1 |
|
return $this->status === self::TRANSPORT_ERROR; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return bool |
|
83
|
|
|
*/ |
|
84
|
10 |
|
public function isSuccess(): bool |
|
85
|
|
|
{ |
|
86
|
10 |
|
return $this->status === self::SUCCESS; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return bool |
|
91
|
|
|
*/ |
|
92
|
|
|
public function isContentMissMatch(): bool |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->status === self::CONTENT_MISS_MATCH; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return bool |
|
99
|
|
|
*/ |
|
100
|
|
|
public function isCodeMissMatch(): bool |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->status === self::CODE_MISS_MATCH; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return null|string |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getDetails() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->status . ': ' . $this->details; |
|
111
|
|
|
} |
|
112
|
|
|
} |