diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 71bb774a..97ad17a0 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -783,6 +783,15 @@
getID()]]>
+
+
+ wrapContext($onFulfilledOrRejected)]]>
+ wrapContext($onFulfilledOrRejected)]]>
+
+
+ $value
+
+
totalMilliseconds]]>
@@ -939,27 +948,18 @@
-
- Scope
- parent::__construct($services, $ctx)
- parent::start($handler, $values)
-
-
- createScope
- getContext
- makeCurrent
- onClose
- parent::__construct($services, $ctx)
- parent::start($handler, $values)
- promise
- startSignal
-
+
+ class Process extends Scope implements ProcessInterface
+
$result
$result
+
+ ProcessInterface
+
Process
@@ -973,69 +973,10 @@
context]]>
-
- services, $this->context)]]>
-
-
- attach
- call
- callSignalHandler
- createScope
- createScope
- defer
- defer
- handleError
- handleError
- makeCurrent
- makeCurrent
- makeCurrent
- makeCurrent
- makeCurrent
- makeCurrent
- makeCurrent
- makeCurrent
- services, $this->context)]]>
- next
- next
- next
- next
- next
- nextPromise
- nextPromise
- nextPromise
- nextPromise
- onClose
- onException
- onException
- onException
- onException
- onException
- onResult
- start
-
-
- detached]]>
- layer]]>
- cancelID]]>
- cancelID]]>
- cancelID]]>
- cancelID]]>
- cancelled]]>
- context]]>
- coroutine]]>
- coroutine]]>
- coroutine]]>
- deferred]]>
- exception]]>
- onCancel]]>
- onCancel]]>
- onCancel]]>
- onCancel]]>
- onClose]]>
- result]]>
- scopeContext]]>
- services]]>
-
+
+ $onFulfilled
+ $onRejected
+
context]]>
@@ -1067,6 +1008,9 @@
resolveConditions
resolveConditions
+
+ $e
+
@@ -1082,14 +1026,6 @@
-
- getLayer
- getLayer
- isCancelled
- onAwait
- startScope
- startScope
-
$onRequest
$parent
@@ -1153,6 +1089,12 @@
$promiseOrValue
$promiseOrValue
+
+ $reasons
+
+
+ $reduce($c, $value, $i++, $total)
+
diff --git a/src/Internal/Promise/Reasons.php b/src/Internal/Promise/Reasons.php
index 0539be30..91ed47da 100644
--- a/src/Internal/Promise/Reasons.php
+++ b/src/Internal/Promise/Reasons.php
@@ -21,7 +21,7 @@
final class Reasons extends RuntimeException implements Iterator, ArrayAccess, Countable
{
/**
- * @param array $collection
+ * @param array $collection
*/
public function __construct(
public array $collection,
@@ -59,11 +59,19 @@ public function offsetExists(mixed $offset): bool
return isset($this->collection[$offset]);
}
+ /**
+ * @param TKey $offset
+ * @return TValue
+ */
public function offsetGet(mixed $offset): Traversable
{
return $this->collection[$offset];
}
+ /**
+ * @param TKey $offset
+ * @param TValue $value
+ */
public function offsetSet(mixed $offset, mixed $value): void
{
$this->collection[$offset] = $value;
diff --git a/src/Internal/Transport/CompletableResult.php b/src/Internal/Transport/CompletableResult.php
index 9f25cbe0..073bad0c 100644
--- a/src/Internal/Transport/CompletableResult.php
+++ b/src/Internal/Transport/CompletableResult.php
@@ -17,6 +17,10 @@
use Temporal\Workflow;
use Temporal\Workflow\WorkflowContextInterface;
+/**
+ * @template T of mixed
+ * @implements CompletableResultInterface
+ */
class CompletableResult implements CompletableResultInterface
{
/**
@@ -41,6 +45,8 @@ class CompletableResult implements CompletableResultInterface
/**
* @var PromiseInterface
+ *
+ * todo: ask Anton why we don't use it in the deferred
*/
private PromiseInterface $promise;
@@ -95,7 +101,11 @@ public function getValue()
}
/**
- * {@inheritDoc}
+ * @param (callable(mixed): mixed)|null $onFulfilled
+ * @param (callable(\Throwable): mixed)|null $onRejected
+ * @param callable|null $onProgress
+ *
+ * @return PromiseInterface
*/
public function then(
?callable $onFulfilled = null,
@@ -108,7 +118,7 @@ public function then(
}
/**
- * @return PromiseInterface
+ * @return PromiseInterface
*/
public function promise(): PromiseInterface
{
@@ -173,6 +183,12 @@ public function always(callable $onFulfilledOrRejected): PromiseInterface
return $this->finally($this->wrapContext($onFulfilledOrRejected));
}
+ /**
+ * @template TParam of mixed
+ * @template TReturn of mixed
+ * @param (callable(TParam): TReturn)|null $callback
+ * @return ($callback is null ? null : (callable(TParam): TReturn))
+ */
private function wrapContext(?callable $callback): ?callable
{
if ($callback === null) {
diff --git a/src/Internal/Workflow/Process/Process.php b/src/Internal/Workflow/Process/Process.php
index cbec76b9..8e5459a0 100644
--- a/src/Internal/Workflow/Process/Process.php
+++ b/src/Internal/Workflow/Process/Process.php
@@ -18,8 +18,12 @@
use Temporal\Internal\ServiceContainer;
use Temporal\Internal\Workflow\WorkflowContext;
use Temporal\Worker\LoopInterface;
+use Temporal\Workflow\CancellationScopeInterface;
use Temporal\Workflow\ProcessInterface;
+/**
+ * @implements CancellationScopeInterface
+ */
class Process extends Scope implements ProcessInterface
{
/**
diff --git a/src/Internal/Workflow/Process/Scope.php b/src/Internal/Workflow/Process/Scope.php
index b9584e25..86eb8efe 100644
--- a/src/Internal/Workflow/Process/Scope.php
+++ b/src/Internal/Workflow/Process/Scope.php
@@ -34,6 +34,7 @@
*
* @internal CoroutineScope is an internal library class, please do not use it in your code.
* @psalm-internal Temporal\Internal\Workflow
+ * @implements CancellationScopeInterface
*/
class Scope implements CancellationScopeInterface
{
diff --git a/src/Promise.php b/src/Promise.php
index d3ca6f48..5c0f25cd 100644
--- a/src/Promise.php
+++ b/src/Promise.php
@@ -12,6 +12,7 @@
namespace Temporal;
use React\Promise\Exception\LengthException;
+use React\Promise\Internal\RejectedPromise;
use React\Promise\PromiseInterface;
use Temporal\Internal\Promise\CancellationQueue;
@@ -207,7 +208,7 @@ static function (mixed $mapped) use ($i, &$values, &$toResolve, $resolve): void
*
* @psalm-param PromiseReduceCallback $reduce
* @param iterable $promises
- * @param callable $reduce
+ * @param callable(mixed $current, mixed $carry, int $current, positive-int $items): mixed $reduce
* @param mixed $initial
* @return PromiseInterface
*/
@@ -297,7 +298,7 @@ public static function resolve($promiseOrValue = null): PromiseInterface
* the value of another promise.
*
* @param $promiseOrValue
- * @return PromiseInterface
+ * @return PromiseInterface
*/
public static function reject($promiseOrValue = null): PromiseInterface
{
@@ -311,8 +312,9 @@ public static function reject($promiseOrValue = null): PromiseInterface
* The returned promise will become **infinitely pending** if `$promisesOrValues`
* contains 0 items.
*
- * @param iterable $promisesOrValues
- * @return PromiseInterface
+ * @template T
+ * @param iterable|T> $promisesOrValues
+ * @return PromiseInterface
*/
public static function race(iterable $promisesOrValues): PromiseInterface
{
diff --git a/src/Workflow/CancellationScopeInterface.php b/src/Workflow/CancellationScopeInterface.php
index 80320640..adf75658 100644
--- a/src/Workflow/CancellationScopeInterface.php
+++ b/src/Workflow/CancellationScopeInterface.php
@@ -13,6 +13,10 @@
use React\Promise\PromiseInterface;
+/**
+ * @template T
+ * @extends PromiseInterface
+ */
interface CancellationScopeInterface extends PromiseInterface
{
/**
diff --git a/src/Workflow/ProcessInterface.php b/src/Workflow/ProcessInterface.php
index 29baaa3d..e35d2787 100644
--- a/src/Workflow/ProcessInterface.php
+++ b/src/Workflow/ProcessInterface.php
@@ -13,6 +13,10 @@
use Temporal\Internal\Repository\Identifiable;
+/**
+ * @template T
+ * @extends CancellationScopeInterface
+ */
interface ProcessInterface extends CancellationScopeInterface, Identifiable
{
/**