Total Complexity | 7 |
Total Lines | 86 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
15 | class Result |
||
16 | { |
||
17 | use Injectable; |
||
18 | |||
19 | /** |
||
20 | * Indicates this result was successful |
||
21 | * |
||
22 | * @var bool |
||
23 | */ |
||
24 | protected $success; |
||
25 | |||
26 | /** |
||
27 | * An message describing the result |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $message = ''; |
||
32 | |||
33 | /** |
||
34 | * Context provided by the handler returning this result |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $context = []; |
||
39 | |||
40 | /** |
||
41 | * @param bool $success |
||
42 | * @param string $message |
||
43 | * @param array $context |
||
44 | */ |
||
45 | public function __construct(bool $success = true, string $message = '', array $context = []) |
||
46 | { |
||
47 | $this->success = $success; |
||
48 | $this->message = $message; |
||
49 | $this->context = $context; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return bool |
||
54 | */ |
||
55 | public function isSuccessful(): bool |
||
56 | { |
||
57 | return $this->success; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @return string |
||
62 | */ |
||
63 | public function getMessage(): string |
||
64 | { |
||
65 | return $this->message; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @return array |
||
70 | */ |
||
71 | public function getContext(): array |
||
72 | { |
||
73 | return $this->context; |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @param bool $success |
||
78 | * @return Result |
||
79 | */ |
||
80 | public function setSuccessful(bool $success): Result |
||
81 | { |
||
82 | return new static($success, $this->getMessage(), $this->getContext()); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @param string $message |
||
87 | * @return Result |
||
88 | */ |
||
89 | public function setMessage(string $message): Result |
||
90 | { |
||
91 | return new static($this->isSuccessful(), $message, $this->getContext()); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @param array $context |
||
96 | * @return Result |
||
97 | */ |
||
98 | public function setContext(array $context): Result |
||
101 | } |
||
102 | } |
||
103 |