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