Skip to content

Commit 7ff136e

Browse files
committed
Merge branch 'master' into activity-retry-policy
2 parents 5c753cf + 728df25 commit 7ff136e

37 files changed

+413
-186
lines changed

psalm-baseline.xml

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -342,34 +342,11 @@
342342
<InvalidArgument>
343343
<code><![CDATA[$message->getDetails()]]></code>
344344
</InvalidArgument>
345-
<MismatchingDocblockParamType>
346-
<code><![CDATA[\ArrayAccess<int, Any>&RepeatedField]]></code>
347-
</MismatchingDocblockParamType>
348-
<MismatchingDocblockPropertyType>
349-
<code><![CDATA[\ArrayAccess<int, Any>&RepeatedField]]></code>
350-
</MismatchingDocblockPropertyType>
351-
<MismatchingDocblockReturnType>
352-
<code><![CDATA[\ArrayAccess<int, Any>&RepeatedField]]></code>
353-
</MismatchingDocblockReturnType>
354345
</file>
355346
<file src="src/Exception/Client/ServiceClientException.php">
356347
<ImplementedReturnTypeMismatch>
357348
<code><![CDATA[RepeatedField]]></code>
358349
</ImplementedReturnTypeMismatch>
359-
<InvalidReturnStatement>
360-
<code><![CDATA[$this->status->getDetails()]]></code>
361-
</InvalidReturnStatement>
362-
<InvalidReturnType>
363-
<code><![CDATA[RepeatedField]]></code>
364-
</InvalidReturnType>
365-
</file>
366-
<file src="src/Exception/Client/UnpackDetailsTrait.php">
367-
<RawObjectIteration>
368-
<code><![CDATA[$details]]></code>
369-
</RawObjectIteration>
370-
<UndefinedInterfaceMethod>
371-
<code><![CDATA[count]]></code>
372-
</UndefinedInterfaceMethod>
373350
</file>
374351
<file src="src/Exception/Client/WorkflowException.php">
375352
<UnsafeInstantiation>
@@ -827,9 +804,6 @@
827804
<NullableReturnStatement>
828805
<code><![CDATA[$mapper]]></code>
829806
</NullableReturnStatement>
830-
<PossibleRawObjectIteration>
831-
<code><![CDATA[$value]]></code>
832-
</PossibleRawObjectIteration>
833807
<PossiblyNullArgument>
834808
<code><![CDATA[$metadata->getDetails()]]></code>
835809
<code><![CDATA[$metadata->getSummary()]]></code>
@@ -997,13 +971,6 @@
997971
<code><![CDATA[$reflection->getName()]]></code>
998972
</PropertyTypeCoercion>
999973
</file>
1000-
<file src="src/Internal/Support/Facade.php">
1001-
<InvalidDocblock>
1002-
<code><![CDATA[object<T>|null]]></code>
1003-
<code><![CDATA[private static ?object $ctx = null;]]></code>
1004-
<code><![CDATA[public static function getCurrentContext(): object]]></code>
1005-
</InvalidDocblock>
1006-
</file>
1007974
<file src="src/Internal/Support/Inheritance.php">
1008975
<PossiblyFalseArgument>
1009976
<code><![CDATA[$implements]]></code>
@@ -1513,16 +1480,9 @@
15131480
</UnsafeInstantiation>
15141481
</file>
15151482
<file src="src/Workflow.php">
1516-
<InvalidReturnStatement>
1517-
<code><![CDATA[self::getCurrentContext()->newActivityStub($class, $options)]]></code>
1518-
<code><![CDATA[self::getCurrentContext()->registerQuery($queryType, $handler, $description)]]></code>
1519-
<code><![CDATA[self::getCurrentContext()->registerSignal($name, $handler, $description)]]></code>
1520-
</InvalidReturnStatement>
1521-
<InvalidReturnType>
1522-
<code><![CDATA[ScopedContextInterface]]></code>
1523-
<code><![CDATA[ScopedContextInterface]]></code>
1524-
<code><![CDATA[T]]></code>
1525-
</InvalidReturnType>
1483+
<UndefinedInterfaceMethod>
1484+
<code><![CDATA[getUpdateContext]]></code>
1485+
</UndefinedInterfaceMethod>
15261486
</file>
15271487
<file src="src/Workflow/ChildWorkflowOptions.php">
15281488
<PossiblyNullReference>

src/Activity.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,32 @@
1717
use Temporal\DataConverter\Type;
1818
use Temporal\DataConverter\ValuesInterface;
1919
use Temporal\Exception\OutOfContextException;
20+
use Temporal\Internal\Activity\ActivityContext;
2021
use Temporal\Internal\Support\Facade;
2122

22-
/**
23-
* @template-extends Facade<ActivityContextInterface>
24-
*/
2523
final class Activity extends Facade
2624
{
25+
/**
26+
* Get the current Activity context.
27+
* @throws OutOfContextException
28+
*/
29+
public static function getCurrentContext(): ActivityContextInterface
30+
{
31+
$ctx = parent::getCurrentContext();
32+
/** @var ActivityContext $ctx */
33+
$ctx::class === ActivityContext::class or throw new OutOfContextException(
34+
'The Activity facade can only be used in the context of an activity execution.',
35+
);
36+
return $ctx;
37+
}
38+
2739
/**
2840
* Returns information about current activity execution.
2941
*
3042
* @throws OutOfContextException in the absence of the activity execution context.
3143
*/
3244
public static function getInfo(): ActivityInfo
3345
{
34-
/** @var ActivityContextInterface $context */
3546
$context = self::getCurrentContext();
3647

3748
return $context->getInfo();
@@ -57,7 +68,6 @@ public static function getInfo(): ActivityInfo
5768
*/
5869
public static function getInput(): ValuesInterface
5970
{
60-
/** @var ActivityContextInterface $context */
6171
$context = self::getCurrentContext();
6272

6373
return $context->getInput();
@@ -72,7 +82,6 @@ public static function getInput(): ValuesInterface
7282
*/
7383
public static function hasHeartbeatDetails(): bool
7484
{
75-
/** @var ActivityContextInterface $context */
7685
$context = self::getCurrentContext();
7786

7887
return $context->hasHeartbeatDetails();
@@ -88,7 +97,6 @@ public static function hasHeartbeatDetails(): bool
8897
*/
8998
public static function getHeartbeatDetails($type = null): mixed
9099
{
91-
/** @var ActivityContextInterface $context */
92100
$context = self::getCurrentContext();
93101

94102
return $context->getLastHeartbeatDetails($type);
@@ -101,7 +109,6 @@ public static function getHeartbeatDetails($type = null): mixed
101109
*/
102110
public static function getCancellationDetails(): ?ActivityCancellationDetails
103111
{
104-
/** @var ActivityContextInterface $context */
105112
$context = self::getCurrentContext();
106113

107114
return $context->getCancellationDetails();
@@ -118,7 +125,6 @@ public static function getCancellationDetails(): ?ActivityCancellationDetails
118125
*/
119126
public static function doNotCompleteOnReturn(): void
120127
{
121-
/** @var ActivityContextInterface $context */
122128
$context = self::getCurrentContext();
123129

124130
$context->doNotCompleteOnReturn();
@@ -150,7 +156,6 @@ public static function doNotCompleteOnReturn(): void
150156
*/
151157
public static function heartbeat($details): void
152158
{
153-
/** @var ActivityContextInterface $context */
154159
$context = self::getCurrentContext();
155160

156161
$context->heartbeat($details);
@@ -161,7 +166,6 @@ public static function heartbeat($details): void
161166
*/
162167
public static function getInstance(): object
163168
{
164-
/** @var ActivityContextInterface $context */
165169
$context = self::getCurrentContext();
166170

167171
return $context->getInstance();

src/Client/Schedule/Action/StartWorkflowAction.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,23 +145,23 @@ public function withWorkflowId(string $workflowId): self
145145
$workflowId !== '' or throw new \InvalidArgumentException('Workflow ID cannot be empty.');
146146

147147
/** @see self::$workflowId */
148-
return $this->with('workflowId', $workflowId);
148+
return $this->cloneWith('workflowId', $workflowId);
149149
}
150150

151151
public function withWorkflowType(string|WorkflowType $workflowType): self
152152
{
153153
\is_string($workflowType) and $workflowType = self::createWorkflowType($workflowType);
154154

155155
/** @see self::$workflowType */
156-
return $this->with('workflowType', $workflowType);
156+
return $this->cloneWith('workflowType', $workflowType);
157157
}
158158

159159
public function withTaskQueue(string|TaskQueue $taskQueue): self
160160
{
161161
\is_string($taskQueue) and $taskQueue = TaskQueue::new($taskQueue);
162162

163163
/** @see self::$taskQueue */
164-
return $this->with('taskQueue', $taskQueue);
164+
return $this->cloneWith('taskQueue', $taskQueue);
165165
}
166166

167167
/**
@@ -174,7 +174,7 @@ public function withInput(array|ValuesInterface $values): self
174174
$values instanceof ValuesInterface or $values = EncodedValues::fromValues($values);
175175

176176
/** @see self::$input */
177-
return $this->with('input', $values);
177+
return $this->cloneWith('input', $values);
178178
}
179179

180180
/**
@@ -189,7 +189,7 @@ public function withWorkflowExecutionTimeout(mixed $timeout): self
189189
: DateInterval::parse($timeout, DateInterval::FORMAT_SECONDS);
190190

191191
/** @see self::$workflowExecutionTimeout */
192-
return $this->with('workflowExecutionTimeout', $timeout);
192+
return $this->cloneWith('workflowExecutionTimeout', $timeout);
193193
}
194194

195195
/**
@@ -204,7 +204,7 @@ public function withWorkflowRunTimeout(mixed $timeout): self
204204
: DateInterval::parse($timeout, DateInterval::FORMAT_SECONDS);
205205

206206
/** @see self::$workflowRunTimeout */
207-
return $this->with('workflowRunTimeout', $timeout);
207+
return $this->cloneWith('workflowRunTimeout', $timeout);
208208
}
209209

210210
/**
@@ -219,13 +219,13 @@ public function withWorkflowTaskTimeout(mixed $timeout): self
219219
: DateInterval::parse($timeout, DateInterval::FORMAT_SECONDS);
220220

221221
/** @see self::$workflowTaskTimeout */
222-
return $this->with('workflowTaskTimeout', $timeout);
222+
return $this->cloneWith('workflowTaskTimeout', $timeout);
223223
}
224224

225225
public function withWorkflowIdReusePolicy(IdReusePolicy $policy): self
226226
{
227227
/** @see self::$workflowIdReusePolicy */
228-
return $this->with('workflowIdReusePolicy', $policy);
228+
return $this->cloneWith('workflowIdReusePolicy', $policy);
229229
}
230230

231231
/**
@@ -234,7 +234,7 @@ public function withWorkflowIdReusePolicy(IdReusePolicy $policy): self
234234
public function withRetryPolicy(RetryOptions $retryPolicy): self
235235
{
236236
/** @see self::$retryPolicy */
237-
return $this->with('retryPolicy', $retryPolicy);
237+
return $this->cloneWith('retryPolicy', $retryPolicy);
238238
}
239239

240240
/**
@@ -247,7 +247,7 @@ public function withMemo(iterable|EncodedCollection $values): self
247247
$values instanceof EncodedCollection or $values = EncodedCollection::fromValues($values);
248248

249249
/** @see self::$memo */
250-
return $this->with('memo', $values);
250+
return $this->cloneWith('memo', $values);
251251
}
252252

253253
/**
@@ -260,7 +260,7 @@ public function withSearchAttributes(iterable|EncodedCollection $values): self
260260
$values instanceof EncodedCollection or $values = EncodedCollection::fromValues($values);
261261

262262
/** @see self::$searchAttributes */
263-
return $this->with('searchAttributes', $values);
263+
return $this->cloneWith('searchAttributes', $values);
264264
}
265265

266266
/**
@@ -273,7 +273,7 @@ public function withHeader(iterable|HeaderInterface $values): self
273273
$values instanceof HeaderInterface or $values = \Temporal\Interceptor\Header::fromValues($values);
274274

275275
/** @see self::$header */
276-
return $this->with('header', $values);
276+
return $this->cloneWith('header', $values);
277277
}
278278

279279
/**
@@ -286,7 +286,7 @@ public function withHeader(iterable|HeaderInterface $values): self
286286
public function withStaticSummary(string $summary): self
287287
{
288288
/** @see self::$userMetadata */
289-
return $this->with('userMetadata', $this->userMetadata->withSummary($summary));
289+
return $this->cloneWith('userMetadata', $this->userMetadata->withSummary($summary));
290290
}
291291

292292
/**
@@ -300,7 +300,7 @@ public function withStaticSummary(string $summary): self
300300
public function withStaticDetails(string $details): self
301301
{
302302
/** @see self::$userMetadata */
303-
return $this->with('userMetadata', $this->userMetadata->withDetails($details));
303+
return $this->cloneWith('userMetadata', $this->userMetadata->withDetails($details));
304304
}
305305

306306
private static function createWorkflowType(string $name): WorkflowType

src/Client/Schedule/BackfillPeriod.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static function new(
5151
public function withStartTime(\DateTimeInterface|string $dateTime): self
5252
{
5353
/** @see self::$startTime */
54-
return $this->with('startTime', DateTime::parse($dateTime, class: \DateTimeImmutable::class));
54+
return $this->cloneWith('startTime', DateTime::parse($dateTime, class: \DateTimeImmutable::class));
5555
}
5656

5757
/**
@@ -60,7 +60,7 @@ public function withStartTime(\DateTimeInterface|string $dateTime): self
6060
public function withEndTime(\DateTimeInterface|string $dateTime): self
6161
{
6262
/** @see self::$endTime */
63-
return $this->with('endTime', DateTime::parse($dateTime, class: \DateTimeImmutable::class));
63+
return $this->cloneWith('endTime', DateTime::parse($dateTime, class: \DateTimeImmutable::class));
6464
}
6565

6666
/**
@@ -69,6 +69,6 @@ public function withEndTime(\DateTimeInterface|string $dateTime): self
6969
public function withOverlapPolicy(ScheduleOverlapPolicy $overlapPolicy): self
7070
{
7171
/** @see self::$overlapPolicy */
72-
return $this->with('overlapPolicy', $overlapPolicy);
72+
return $this->cloneWith('overlapPolicy', $overlapPolicy);
7373
}
7474
}

src/Client/Schedule/Policy/SchedulePolicies.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static function new(): self
6767
*/
6868
public function withOverlapPolicy(ScheduleOverlapPolicy $overlapPolicy): self
6969
{
70-
return $this->with('overlapPolicy', $overlapPolicy);
70+
return $this->cloneWith('overlapPolicy', $overlapPolicy);
7171
}
7272

7373
/**
@@ -86,7 +86,7 @@ public function withCatchupWindow(mixed $interval): self
8686
// Can't be less than 10 seconds.
8787
\assert($interval->totalSeconds >= 10);
8888

89-
return $this->with('catchupWindow', $interval);
89+
return $this->cloneWith('catchupWindow', $interval);
9090
}
9191

9292
/**
@@ -96,6 +96,6 @@ public function withCatchupWindow(mixed $interval): self
9696
*/
9797
public function withPauseOnFailure(bool $pauseOnFailure = true): self
9898
{
99-
return $this->with('pauseOnFailure', $pauseOnFailure);
99+
return $this->cloneWith('pauseOnFailure', $pauseOnFailure);
100100
}
101101
}

src/Client/Schedule/Schedule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,24 @@ public static function new(): self
6060
public function withAction(?ScheduleAction $action): self
6161
{
6262
/** @see self::$action */
63-
return $this->with('action', $action);
63+
return $this->cloneWith('action', $action);
6464
}
6565

6666
public function withSpec(ScheduleSpec $spec): self
6767
{
6868
/** @see self::$spec */
69-
return $this->with('spec', $spec);
69+
return $this->cloneWith('spec', $spec);
7070
}
7171

7272
public function withPolicies(SchedulePolicies $policies): self
7373
{
7474
/** @see self::$policies */
75-
return $this->with('policies', $policies);
75+
return $this->cloneWith('policies', $policies);
7676
}
7777

7878
public function withState(ScheduleState $state): self
7979
{
8080
/** @see self::$state */
81-
return $this->with('state', $state);
81+
return $this->cloneWith('state', $state);
8282
}
8383
}

0 commit comments

Comments
 (0)