@@ -76,6 +76,8 @@ final class WorkflowStub
7676 * @param list<mixed> $memo Specifies additional non-indexed information in result of list workflow.
7777 *
7878 * @return ($type is class-string ? T|WorkflowProxy : WorkflowStubInterface)
79+ *
80+ * @psalm-suppress LessSpecificReturnStatement,MoreSpecificReturnType
7981 */
8082 public static function workflow (
8183 WorkflowClientInterface $ workflowClient ,
@@ -97,8 +99,11 @@ public static function workflow(
9799 array $ searchAttributes = [],
98100 array $ memo = [],
99101 ): object {
100- $ isUntyped = !\class_exists ($ type ) && !\interface_exists ($ type );
101- $ attributes = $ isUntyped ? new AttributeCollection ([]) : self ::readAttributes ($ type );
102+ $ isTyped = self ::isClassOrInterface ($ type );
103+ /** @psalm-suppress ArgumentTypeCoercion */
104+ $ attributes = $ isTyped
105+ ? self ::readAttributes ($ type )
106+ : new AttributeCollection ([]);
102107
103108 // Retry options
104109 $ retryOptions = RetryOptions::create (
@@ -129,9 +134,10 @@ public static function workflow(
129134 $ searchAttributes === [] or $ options = $ options ->withSearchAttributes ($ searchAttributes );
130135 $ memo === [] or $ options = $ options ->withMemo ($ memo );
131136
132- return $ isUntyped
133- ? $ workflowClient ->newUntypedWorkflowStub ($ type , $ options )
134- : $ workflowClient ->newWorkflowStub ($ type , $ options );
137+ /** @psalm-suppress ArgumentTypeCoercion */
138+ return $ isTyped
139+ ? $ workflowClient ->newWorkflowStub ($ type , $ options )
140+ : $ workflowClient ->newUntypedWorkflowStub ($ type , $ options );
135141 }
136142
137143 /**
@@ -181,6 +187,8 @@ public static function workflow(
181187 * @param list<mixed> $memo Specifies additional non-indexed information in result of list workflow.
182188 *
183189 * @return ($type is class-string ? T|ChildWorkflowProxy : ChildWorkflowStubInterface)
190+ *
191+ * @psalm-suppress LessSpecificReturnStatement,MoreSpecificReturnType
184192 */
185193 public static function childWorkflow (
186194 string $ type ,
@@ -202,8 +210,11 @@ public static function childWorkflow(
202210 array $ searchAttributes = [],
203211 array $ memo = [],
204212 ): object {
205- $ isUntyped = !\class_exists ($ type ) && !\interface_exists ($ type );
206- $ attributes = $ isUntyped ? new AttributeCollection ([]) : self ::readAttributes ($ type );
213+ $ isTyped = self ::isClassOrInterface ($ type );
214+ /** @psalm-suppress ArgumentTypeCoercion */
215+ $ attributes = $ isTyped
216+ ? self ::readAttributes ($ type )
217+ : new AttributeCollection ([]);
207218
208219 // Retry options
209220 $ retryOptions = RetryOptions::create (
@@ -239,9 +250,10 @@ public static function childWorkflow(
239250 $ searchAttributes === [] or $ options = $ options ->withSearchAttributes ($ searchAttributes );
240251 $ memo === [] or $ options = $ options ->withMemo ($ memo );
241252
242- return $ isUntyped
243- ? Workflow::newUntypedChildWorkflowStub ($ type , $ options )
244- : Workflow::newChildWorkflowStub ($ type , $ options );
253+ /** @psalm-suppress ArgumentTypeCoercion */
254+ return $ isTyped
255+ ? Workflow::newChildWorkflowStub ($ type , $ options )
256+ : Workflow::newUntypedChildWorkflowStub ($ type , $ options );
245257 }
246258
247259 /**
@@ -251,4 +263,14 @@ private static function readAttributes(string $class): AttributeCollection
251263 {
252264 return AttributeReader::collectionFromClass ($ class , [AttributeForWorkflow::class]);
253265 }
266+
267+ /**
268+ * @param non-empty-string $type
269+ * @psalm-assert-if-true class-string $type
270+ * @psalm-assert-if-false non-empty-string $type
271+ */
272+ private static function isClassOrInterface (string $ type ): bool
273+ {
274+ return \class_exists ($ type ) || \interface_exists ($ type );
275+ }
254276}
0 commit comments