@@ -48,12 +48,15 @@ public static function run(Configuration $config, TaskInterface $task): mixed
4848 *
4949 * @param callable():TArgResult $context
5050 *
51- * @return \Generator<mixed, array-key , Step, TArgResult>
51+ * @return \Generator<mixed, Step , Step, TArgResult>
5252 * @throws \Throwable
5353 */
5454 public static function capture (callable $ context ): \Generator
5555 {
56- return self ::toCoroutine (new \Fiber ($ context ));
56+ /** @var \Fiber<Step, Step, TArgResult, Step> $fiber */
57+ $ fiber = new \Fiber ($ context );
58+
59+ return self ::toCoroutine ($ fiber );
5760 }
5861
5962 /**
@@ -69,7 +72,7 @@ public static function notify(string $message, array $args = []): void
6972 }
7073
7174 try {
72- \Fiber::suspend (new NotifyStep ($ message , $ args ));
75+ \Fiber::suspend (new NotifyStep ($ message , \array_values ( $ args) ));
7376 } catch (\Throwable ) {
7477 // NO-OP
7578 }
@@ -88,7 +91,7 @@ public static function progress(string $message, array $args = []): void
8891 }
8992
9093 try {
91- \Fiber::suspend (new ProgressStep ($ message , $ args ));
94+ \Fiber::suspend (new ProgressStep ($ message , \array_values ( $ args) ));
9295 } catch (\Throwable ) {
9396 // NO-OP
9497 }
@@ -105,19 +108,19 @@ public static function info(string $message, array $args = []): void
105108 }
106109
107110 try {
108- \Fiber::suspend (new InfoStep ($ message , $ args ));
111+ \Fiber::suspend (new InfoStep ($ message , \array_values ( $ args) ));
109112 } catch (\Throwable ) {
110113 // NO-OP
111114 }
112115 }
113116
114117 /**
115- * @template TArgStep of Step
118+ * @template TArgStep of Step|null
116119 * @template TArgResult of mixed
117120 *
118- * @param \Fiber<null, null , TArgResult, TArgStep> $fiber
121+ * @param \Fiber<TArgStep, TArgStep , TArgResult, TArgStep> $fiber
119122 *
120- * @return \Generator<null, array-key, TArgStep, TArgResult>
123+ * @return \Generator<array-key, TArgStep , TArgStep, TArgResult>
121124 * @throws \Throwable
122125 */
123126 private static function toCoroutine (\Fiber $ fiber ): \Generator
@@ -129,26 +132,30 @@ private static function toCoroutine(\Fiber $fiber): \Generator
129132 }
130133
131134 if (!$ fiber ->isStarted ()) {
135+ /** @phpstan-ignore generator.valueType */
132136 $ value = yield $ fiber ->start ();
133137 }
134138
135- if (!$ fiber ->isTerminated ()) {
136- while (true ) {
137- $ value = $ fiber ->resume ($ value );
138-
139- // The last call to "resume()" moves the execution of the
140- // Fiber to the "return" stmt.
141- //
142- // So the "yield" is not needed. Skip this step and return
143- // the result.
144- if ($ fiber ->isTerminated ()) {
145- break ;
146- }
147-
148- $ value = yield $ value ;
139+ /** @phpstan-ignore booleanNot.alwaysTrue */
140+ while (!$ fiber ->isTerminated ()) {
141+ /** @phpstan-ignore argument.type */
142+ $ value = $ fiber ->resume ($ value );
143+
144+ // The last call to "resume()" moves the execution of the
145+ // Fiber to the "return" stmt.
146+ //
147+ // So the "yield" is not needed. Skip this step and return
148+ // the result.
149+ /** @phpstan-ignore if.alwaysFalse */
150+ if ($ fiber ->isTerminated ()) {
151+ break ;
149152 }
153+
154+ /** @phpstan-ignore generator.valueType */
155+ $ value = yield $ value ;
150156 }
151157
158+ /** @phpstan-ignore deadCode.unreachable */
152159 return $ fiber ->getReturn ();
153160 }
154161}
0 commit comments