diff --git a/src/Psl/Result/ResultInterface.php b/src/Psl/Result/ResultInterface.php index 2a29a951..2b5209bd 100644 --- a/src/Psl/Result/ResultInterface.php +++ b/src/Psl/Result/ResultInterface.php @@ -53,6 +53,8 @@ public function getThrowable(): Throwable; * @return bool - `true` if the operation succeeded; `false` otherwise * * @psalm-mutation-free + * + * @psalm-assert-if-true Success $this */ public function isSucceeded(): bool; @@ -64,6 +66,8 @@ public function isSucceeded(): bool; * @return bool - `true` if the operation failed; `false` otherwise * * @psalm-mutation-free + * + * @psalm-assert-if-true Failure $this */ public function isFailed(): bool; diff --git a/tests/static-analysis/Result/result_interface.php b/tests/static-analysis/Result/result_interface.php new file mode 100644 index 00000000..1ede9fcc --- /dev/null +++ b/tests/static-analysis/Result/result_interface.php @@ -0,0 +1,42 @@ + $result + * + * @throws Exception + * + * @return Failure + */ +function return_failure(ResultInterface $result): Failure +{ + if ($result->isFailed()) { + return $result; + } + + throw new Exception(); +} + +/** + * @param ResultInterface $result + * + * @throws Exception + * + * @return Success + */ +function return_success(ResultInterface $result): Success +{ + if ($result->isSucceeded()) { + return $result; + } + + throw new Exception(); +}