File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
tests/static-analysis/Result Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,8 @@ public function getThrowable(): Throwable;
115
115
* @return bool - `true` if the operation succeeded; `false` otherwise
116
116
*
117
117
* @psalm-mutation-free
118
+ *
119
+ * @psalm-assert-if-true Success<T> $this
118
120
*/
119
121
public function isSucceeded (): bool ;
120
122
@@ -126,6 +128,8 @@ public function isSucceeded(): bool;
126
128
* @return bool - `true` if the operation failed; `false` otherwise
127
129
*
128
130
* @psalm-mutation-free
131
+ *
132
+ * @psalm-assert-if-true Failure<T> $this
129
133
*/
130
134
public function isFailed (): bool ;
131
135
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Psl \Tests \StaticAnalysis \Iter ;
6
+
7
+ use Exception ;
8
+ use Psl \Result \Failure ;
9
+ use Psl \Result \ResultInterface ;
10
+ use Psl \Result \Success ;
11
+
12
+ /**
13
+ * @param ResultInterface<int> $result
14
+ *
15
+ * @throws Exception
16
+ *
17
+ * @return Failure<int, Exception>
18
+ */
19
+ function return_failure (ResultInterface $ result ): Failure
20
+ {
21
+ if ($ result ->isFailed ()) {
22
+ return $ result ;
23
+ }
24
+
25
+ throw new Exception ();
26
+ }
27
+
28
+ /**
29
+ * @param ResultInterface<int> $result
30
+ *
31
+ * @throws Exception
32
+ *
33
+ * @return Success<int>
34
+ */
35
+ function return_success (ResultInterface $ result ): Success
36
+ {
37
+ if ($ result ->isSucceeded ()) {
38
+ return $ result ;
39
+ }
40
+
41
+ throw new Exception ();
42
+ }
You can’t perform that action at this time.
0 commit comments