diff --git a/src/Factory/ActivityStub.php b/src/Factory/ActivityStub.php index 3226a6f..537defa 100644 --- a/src/Factory/ActivityStub.php +++ b/src/Factory/ActivityStub.php @@ -59,6 +59,8 @@ final class ActivityStub * completed, cancel accepted). {@see \Temporal\Activity\ActivityCancellationType} * * @return ($class is class-string ? T|ActivityProxy : ActivityStubInterface) + * + * @psalm-suppress LessSpecificReturnStatement,MoreSpecificReturnType */ public static function activity( ?string $class = null, @@ -98,7 +100,7 @@ public static function activity( $heartbeatTimeout === 0 or $options = $options->withHeartbeatTimeout($heartbeatTimeout); // Activity ID $activityId === null or $options = $options->withActivityId((string)$activityId); - $cancellationType === null or $options = $options->withCancellationType($cancellationType); + $cancellationType === 0 or $options = $options->withCancellationType($cancellationType); return $class === null ? Workflow::newUntypedActivityStub($options) diff --git a/src/Factory/WorkflowStub.php b/src/Factory/WorkflowStub.php index d2c58a1..f5f13e6 100644 --- a/src/Factory/WorkflowStub.php +++ b/src/Factory/WorkflowStub.php @@ -76,6 +76,8 @@ final class WorkflowStub * @param list $memo Specifies additional non-indexed information in result of list workflow. * * @return ($type is class-string ? T|WorkflowProxy : WorkflowStubInterface) + * + * @psalm-suppress LessSpecificReturnStatement,MoreSpecificReturnType */ public static function workflow( WorkflowClientInterface $workflowClient, @@ -97,8 +99,11 @@ public static function workflow( array $searchAttributes = [], array $memo = [], ): object { - $isUntyped = !\class_exists($type) && !\interface_exists($type); - $attributes = $isUntyped ? new AttributeCollection([]) : self::readAttributes($type); + $isTyped = self::isClassOrInterface($type); + /** @psalm-suppress ArgumentTypeCoercion */ + $attributes = $isTyped + ? self::readAttributes($type) + : new AttributeCollection([]); // Retry options $retryOptions = RetryOptions::create( @@ -129,9 +134,10 @@ public static function workflow( $searchAttributes === [] or $options = $options->withSearchAttributes($searchAttributes); $memo === [] or $options = $options->withMemo($memo); - return $isUntyped - ? $workflowClient->newUntypedWorkflowStub($type, $options) - : $workflowClient->newWorkflowStub($type, $options); + /** @psalm-suppress ArgumentTypeCoercion */ + return $isTyped + ? $workflowClient->newWorkflowStub($type, $options) + : $workflowClient->newUntypedWorkflowStub($type, $options); } /** @@ -181,6 +187,8 @@ public static function workflow( * @param list $memo Specifies additional non-indexed information in result of list workflow. * * @return ($type is class-string ? T|ChildWorkflowProxy : ChildWorkflowStubInterface) + * + * @psalm-suppress LessSpecificReturnStatement,MoreSpecificReturnType */ public static function childWorkflow( string $type, @@ -202,8 +210,11 @@ public static function childWorkflow( array $searchAttributes = [], array $memo = [], ): object { - $isUntyped = !\class_exists($type) && !\interface_exists($type); - $attributes = $isUntyped ? new AttributeCollection([]) : self::readAttributes($type); + $isTyped = self::isClassOrInterface($type); + /** @psalm-suppress ArgumentTypeCoercion */ + $attributes = $isTyped + ? self::readAttributes($type) + : new AttributeCollection([]); // Retry options $retryOptions = RetryOptions::create( @@ -239,9 +250,10 @@ public static function childWorkflow( $searchAttributes === [] or $options = $options->withSearchAttributes($searchAttributes); $memo === [] or $options = $options->withMemo($memo); - return $isUntyped - ? Workflow::newUntypedChildWorkflowStub($type, $options) - : Workflow::newChildWorkflowStub($type, $options); + /** @psalm-suppress ArgumentTypeCoercion */ + return $isTyped + ? Workflow::newChildWorkflowStub($type, $options) + : Workflow::newUntypedChildWorkflowStub($type, $options); } /** @@ -251,4 +263,14 @@ private static function readAttributes(string $class): AttributeCollection { return AttributeReader::collectionFromClass($class, [AttributeForWorkflow::class]); } + + /** + * @param non-empty-string $type + * @psalm-assert-if-true class-string $type + * @psalm-assert-if-false non-empty-string $type + */ + private static function isClassOrInterface(string $type): bool + { + return \class_exists($type) || \interface_exists($type); + } } diff --git a/src/Internal/Attribute/AttributeCollection.php b/src/Internal/Attribute/AttributeCollection.php index a95ecd2..86bb3d2 100644 --- a/src/Internal/Attribute/AttributeCollection.php +++ b/src/Internal/Attribute/AttributeCollection.php @@ -47,20 +47,19 @@ public function first(string $class): ?object return $result; } - public function has(string $class): bool - { - return $this->count($this->attributes[$class]) > 0; - } - /** + * @param class-string $class * @return int<0, max> */ public function count(string $class): int { $this->makeIndex($class); - return \count($this->attributes[$class]); + return \count($this->attributes[$class] ?? []); } + /** + * @param class-string $class + */ private function makeIndex(string $class): void { if (\array_key_exists($class, $this->attributes)) { diff --git a/src/Internal/Attribute/AttributeReader.php b/src/Internal/Attribute/AttributeReader.php index 1267413..0f3c4fc 100644 --- a/src/Internal/Attribute/AttributeReader.php +++ b/src/Internal/Attribute/AttributeReader.php @@ -100,6 +100,9 @@ private static function fetchAttributes(\ReflectionClass $reflection, array $fil return $result; } + /** + * @return list + */ private static function sortInterfaces(\ReflectionClass $class): array { $result = []; diff --git a/src/Internal/RetryOptions.php b/src/Internal/RetryOptions.php index ca9c4b0..b1daa22 100644 --- a/src/Internal/RetryOptions.php +++ b/src/Internal/RetryOptions.php @@ -51,6 +51,7 @@ public static function create( $retryAttempts > 0 and $retryOptions = $retryOptions->withMaximumAttempts($retryAttempts); $retryInitInterval === null or $retryOptions = $retryOptions->withInitialInterval($retryInitInterval); $retryMaxInterval === null or $retryOptions = $retryOptions->withMaximumInterval($retryMaxInterval); + /** @psalm-suppress PossiblyNullArgument */ $retryBackoff >= 1.0 and $retryOptions = $retryOptions->withBackoffCoefficient($retryBackoff); $nonRetryables === [] or $retryOptions = $retryOptions->withNonRetryableExceptions($nonRetryables); return $retryOptions; diff --git a/src/VirtualPromise.php b/src/VirtualPromise.php index bac8bbf..b0bca64 100644 --- a/src/VirtualPromise.php +++ b/src/VirtualPromise.php @@ -31,6 +31,8 @@ * } * } * ``` + * + * @psalm-suppress TooManyTemplateParams */ interface VirtualPromise extends PromiseInterface {