Skip to content

Commit c94a7c0

Browse files
committed
chore: Fix tests and psalm issues
1 parent 4ce113b commit c94a7c0

File tree

6 files changed

+19
-21
lines changed

6 files changed

+19
-21
lines changed

src/Internal/Transport/Router/StartWorkflow.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use Temporal\Internal\Workflow\WorkflowContext;
2626
use Temporal\Worker\FeatureFlags;
2727
use Temporal\Worker\Transport\Command\ServerRequestInterface;
28-
use Temporal\Workflow;
2928
use Temporal\Workflow\WorkflowInfo;
3029

3130
final class StartWorkflow extends Route
@@ -90,7 +89,6 @@ public function handle(ServerRequestInterface $request, array $headers, Deferred
9089
);
9190
$runId = $request->getID();
9291

93-
Workflow::setCurrentContext($context);
9492
$process = new Process($this->services, $runId, $instance);
9593
$this->services->running->add($process);
9694
$resolver->resolve(EncodedValues::fromValues([null]));

src/Internal/Workflow/ActivityStub.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ public function execute(
7070

7171
protected function request(RequestInterface $request): PromiseInterface
7272
{
73-
/** @var Workflow\WorkflowContextInterface $context */
74-
$context = Workflow::getCurrentContext();
75-
76-
return $context->request($request);
73+
return Workflow::getCurrentContext()->request($request);
7774
}
7875
}

src/Internal/Workflow/ChildWorkflowStub.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ function (WorkflowExecution $execution) use ($name, $args) {
125125

126126
protected function request(RequestInterface $request, bool $cancellable = true): PromiseInterface
127127
{
128-
/** @var Workflow\WorkflowContextInterface $context */
129-
$context = Workflow::getCurrentContext();
130-
131-
return $context->request($request, cancellable: $cancellable);
128+
return Workflow::getCurrentContext()->request($request, cancellable: $cancellable);
132129
}
133130

134131
private function getOptionArray(): array

src/Internal/Workflow/ExternalWorkflowStub.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public function cancel(): PromiseInterface
7777
private function request(RequestInterface $request): PromiseInterface
7878
{
7979
// todo intercept
80-
/** @var Workflow\WorkflowContextInterface $context */
8180
$context = Workflow::getCurrentContext();
8281

8382
return $context->request($request);

src/Workflow.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use Temporal\Exception\Failure\CanceledFailure;
2424
use Temporal\Exception\OutOfContextException;
2525
use Temporal\Internal\Support\Facade;
26-
use Temporal\Internal\Workflow\ScopeContext;
2726
use Temporal\Workflow\ActivityStubInterface;
2827
use Temporal\Workflow\CancellationScopeInterface;
2928
use Temporal\Workflow\ChildWorkflowOptions;
@@ -57,11 +56,10 @@ final class Workflow extends Facade
5756
* Get the current Workflow context.
5857
* @throws OutOfContextException
5958
*/
60-
public static function getCurrentContext(): ScopedContextInterface
59+
public static function getCurrentContext(): WorkflowContextInterface
6160
{
6261
$ctx = parent::getCurrentContext();
63-
/** @var ScopeContext $ctx */
64-
$ctx::class === ScopeContext::class or throw new OutOfContextException(
62+
$ctx instanceof WorkflowContextInterface or throw new OutOfContextException(
6563
'The Workflow facade can be used only inside workflow code.',
6664
);
6765
return $ctx;
@@ -202,7 +200,9 @@ public static function getInput(): ValuesInterface
202200
*/
203201
public static function async(callable $task): CancellationScopeInterface
204202
{
205-
return self::getCurrentContext()->async($task);
203+
$ctx = self::getCurrentContext();
204+
\assert($ctx instanceof ScopedContextInterface);
205+
return $ctx->async($task);
206206
}
207207

208208
/**
@@ -254,7 +254,9 @@ public static function async(callable $task): CancellationScopeInterface
254254
*/
255255
public static function asyncDetached(callable $task): CancellationScopeInterface
256256
{
257-
return self::getCurrentContext()->asyncDetached($task);
257+
$ctx = self::getCurrentContext();
258+
\assert($ctx instanceof ScopedContextInterface);
259+
return $ctx->asyncDetached($task);
258260
}
259261

260262
/**
@@ -362,7 +364,9 @@ public static function registerQuery(
362364
callable $handler,
363365
string $description = '',
364366
): ScopedContextInterface {
365-
return self::getCurrentContext()->registerQuery($queryType, $handler, $description);
367+
$ctx = self::getCurrentContext();
368+
\assert($ctx instanceof ScopedContextInterface);
369+
return $ctx->registerQuery($queryType, $handler, $description);
366370
}
367371

368372
/**
@@ -382,7 +386,9 @@ public static function registerQuery(
382386
*/
383387
public static function registerSignal(string $name, callable $handler, string $description = ''): ScopedContextInterface
384388
{
385-
return self::getCurrentContext()->registerSignal($name, $handler, $description);
389+
$ctx = self::getCurrentContext();
390+
\assert($ctx instanceof ScopedContextInterface);
391+
return $ctx->registerSignal($name, $handler, $description);
386392
}
387393

388394
/**
@@ -501,7 +507,9 @@ public static function registerUpdate(
501507
?callable $validator = null,
502508
string $description = '',
503509
): ScopedContextInterface {
504-
return self::getCurrentContext()->registerUpdate($name, $handler, $validator, $description);
510+
$ctx = self::getCurrentContext();
511+
\assert($ctx instanceof ScopedContextInterface);
512+
return $ctx->registerUpdate($name, $handler, $validator, $description);
505513
}
506514

507515
/**

src/Workflow/WorkflowContextInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Temporal\Common\SearchAttributes\SearchAttributeUpdate;
2020
use Temporal\DataConverter\Type;
2121
use Temporal\DataConverter\ValuesInterface;
22-
use Temporal\Exception\OutOfContextException;
2322
use Temporal\Internal\Support\DateInterval;
2423
use Temporal\Worker\Transport\Command\RequestInterface;
2524
use Temporal\Worker\Environment\EnvironmentInterface;

0 commit comments

Comments
 (0)