Skip to content

Commit b9ab40b

Browse files
committed
Fix psalm issues
1 parent 3ff4de8 commit b9ab40b

6 files changed

Lines changed: 46 additions & 17 deletions

File tree

src/Factory/ActivityStub.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ final class ActivityStub
5959
* completed, cancel accepted). {@see \Temporal\Activity\ActivityCancellationType}
6060
*
6161
* @return ($class is class-string ? T|ActivityProxy : ActivityStubInterface)
62+
*
63+
* @psalm-suppress LessSpecificReturnStatement,MoreSpecificReturnType
6264
*/
6365
public static function activity(
6466
?string $class = null,
@@ -98,7 +100,7 @@ public static function activity(
98100
$heartbeatTimeout === 0 or $options = $options->withHeartbeatTimeout($heartbeatTimeout);
99101
// Activity ID
100102
$activityId === null or $options = $options->withActivityId((string)$activityId);
101-
$cancellationType === null or $options = $options->withCancellationType($cancellationType);
103+
$cancellationType === 0 or $options = $options->withCancellationType($cancellationType);
102104

103105
return $class === null
104106
? Workflow::newUntypedActivityStub($options)

src/Factory/WorkflowStub.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/Internal/Attribute/AttributeCollection.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,19 @@ public function first(string $class): ?object
4747
return $result;
4848
}
4949

50-
public function has(string $class): bool
51-
{
52-
return $this->count($this->attributes[$class]) > 0;
53-
}
54-
5550
/**
51+
* @param class-string $class
5652
* @return int<0, max>
5753
*/
5854
public function count(string $class): int
5955
{
6056
$this->makeIndex($class);
61-
return \count($this->attributes[$class]);
57+
return \count($this->attributes[$class] ?? []);
6258
}
6359

60+
/**
61+
* @param class-string $class
62+
*/
6463
private function makeIndex(string $class): void
6564
{
6665
if (\array_key_exists($class, $this->attributes)) {

src/Internal/Attribute/AttributeReader.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ private static function fetchAttributes(\ReflectionClass $reflection, array $fil
100100
return $result;
101101
}
102102

103+
/**
104+
* @return list<class-string>
105+
*/
103106
private static function sortInterfaces(\ReflectionClass $class): array
104107
{
105108
$result = [];

src/Internal/RetryOptions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public static function create(
5151
$retryAttempts > 0 and $retryOptions = $retryOptions->withMaximumAttempts($retryAttempts);
5252
$retryInitInterval === null or $retryOptions = $retryOptions->withInitialInterval($retryInitInterval);
5353
$retryMaxInterval === null or $retryOptions = $retryOptions->withMaximumInterval($retryMaxInterval);
54+
/** @psalm-suppress PossiblyNullArgument */
5455
$retryBackoff >= 1.0 and $retryOptions = $retryOptions->withBackoffCoefficient($retryBackoff);
5556
$nonRetryables === [] or $retryOptions = $retryOptions->withNonRetryableExceptions($nonRetryables);
5657
return $retryOptions;

src/VirtualPromise.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
* }
3232
* }
3333
* ```
34+
*
35+
* @psalm-suppress TooManyTemplateParams
3436
*/
3537
interface VirtualPromise extends PromiseInterface
3638
{

0 commit comments

Comments
 (0)