-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: narrow ResultInterface to concrete implementation after calling…
… `isSucceeded()` and `isFailed()`
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psl\Tests\StaticAnalysis\Iter; | ||
|
||
use Exception; | ||
use Psl\Result\Failure; | ||
use Psl\Result\ResultInterface; | ||
use Psl\Result\Success; | ||
|
||
/** | ||
* @param ResultInterface<int> $result | ||
* | ||
* @throws Exception | ||
* | ||
* @return Failure<int, Exception> | ||
*/ | ||
function return_failure(ResultInterface $result): Failure | ||
{ | ||
if ($result->isFailed()) { | ||
return $result; | ||
} | ||
|
||
throw new Exception(); | ||
} | ||
|
||
/** | ||
* @param ResultInterface<int> $result | ||
* | ||
* @throws Exception | ||
* | ||
* @return Success<int> | ||
*/ | ||
function return_success(ResultInterface $result): Success | ||
{ | ||
if ($result->isSucceeded()) { | ||
return $result; | ||
} | ||
|
||
throw new Exception(); | ||
} |