Skip to content

Commit

Permalink
Fix psalm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Sep 14, 2023
1 parent d25a629 commit e9b1351
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 93 deletions.
114 changes: 28 additions & 86 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,15 @@
<code><![CDATA[$command->getID()]]></code>
</PossiblyInvalidArgument>
</file>
<file src="src/Internal/Transport/CompletableResult.php">
<InvalidArgument>
<code><![CDATA[$this->wrapContext($onFulfilledOrRejected)]]></code>
<code><![CDATA[$this->wrapContext($onFulfilledOrRejected)]]></code>
</InvalidArgument>
<PossiblyNullArgument>
<code>$value</code>
</PossiblyNullArgument>
</file>
<file src="src/Internal/Transport/Request/NewTimer.php">
<PossiblyNullPropertyFetch>
<code><![CDATA[CarbonInterval::make($interval)->totalMilliseconds]]></code>
Expand Down Expand Up @@ -939,27 +948,18 @@
</MoreSpecificReturnType>
</file>
<file src="src/Internal/Workflow/Process/Process.php">
<InternalClass>
<code>Scope</code>
<code>parent::__construct($services, $ctx)</code>
<code>parent::start($handler, $values)</code>
</InternalClass>
<InternalMethod>
<code>createScope</code>
<code>getContext</code>
<code>makeCurrent</code>
<code>onClose</code>
<code>parent::__construct($services, $ctx)</code>
<code>parent::start($handler, $values)</code>
<code>promise</code>
<code>startSignal</code>
</InternalMethod>
<InvalidDocblock>
<code>class Process extends Scope implements ProcessInterface</code>
</InvalidDocblock>
<MissingClosureParamType>
<code>$result</code>
</MissingClosureParamType>
<MissingParamType>
<code>$result</code>
</MissingParamType>
<MissingTemplateParam>
<code>ProcessInterface</code>
</MissingTemplateParam>
<PropertyNotSetInConstructor>
<code>Process</code>
</PropertyNotSetInConstructor>
Expand All @@ -973,69 +973,10 @@
<ArgumentTypeCoercion>
<code><![CDATA[$this->context]]></code>
</ArgumentTypeCoercion>
<InternalClass>
<code><![CDATA[new Scope($this->services, $this->context)]]></code>
</InternalClass>
<InternalMethod>
<code>attach</code>
<code>call</code>
<code>callSignalHandler</code>
<code>createScope</code>
<code>createScope</code>
<code>defer</code>
<code>defer</code>
<code>handleError</code>
<code>handleError</code>
<code>makeCurrent</code>
<code>makeCurrent</code>
<code>makeCurrent</code>
<code>makeCurrent</code>
<code>makeCurrent</code>
<code>makeCurrent</code>
<code>makeCurrent</code>
<code>makeCurrent</code>
<code><![CDATA[new Scope($this->services, $this->context)]]></code>
<code>next</code>
<code>next</code>
<code>next</code>
<code>next</code>
<code>next</code>
<code>nextPromise</code>
<code>nextPromise</code>
<code>nextPromise</code>
<code>nextPromise</code>
<code>onClose</code>
<code>onException</code>
<code>onException</code>
<code>onException</code>
<code>onException</code>
<code>onException</code>
<code>onResult</code>
<code>start</code>
</InternalMethod>
<InternalProperty>
<code><![CDATA[$scope->detached]]></code>
<code><![CDATA[$scope->layer]]></code>
<code><![CDATA[$this->cancelID]]></code>
<code><![CDATA[$this->cancelID]]></code>
<code><![CDATA[$this->cancelID]]></code>
<code><![CDATA[$this->cancelID]]></code>
<code><![CDATA[$this->cancelled]]></code>
<code><![CDATA[$this->context]]></code>
<code><![CDATA[$this->coroutine]]></code>
<code><![CDATA[$this->coroutine]]></code>
<code><![CDATA[$this->coroutine]]></code>
<code><![CDATA[$this->deferred]]></code>
<code><![CDATA[$this->exception]]></code>
<code><![CDATA[$this->onCancel]]></code>
<code><![CDATA[$this->onCancel]]></code>
<code><![CDATA[$this->onCancel]]></code>
<code><![CDATA[$this->onCancel]]></code>
<code><![CDATA[$this->onClose]]></code>
<code><![CDATA[$this->result]]></code>
<code><![CDATA[$this->scopeContext]]></code>
<code><![CDATA[$this->services]]></code>
</InternalProperty>
<InvalidArgument>
<code>$onFulfilled</code>
<code>$onRejected</code>
</InvalidArgument>
<LessSpecificReturnStatement>
<code><![CDATA[$this->context]]></code>
</LessSpecificReturnStatement>
Expand Down Expand Up @@ -1067,6 +1008,9 @@
<code>resolveConditions</code>
<code>resolveConditions</code>
</UndefinedInterfaceMethod>
<UnusedClosureParam>
<code>$e</code>
</UnusedClosureParam>
</file>
<file src="src/Internal/Workflow/ProcessCollection.php">
<DocblockTypeContradiction>
Expand All @@ -1082,14 +1026,6 @@
</PossiblyNullReference>
</file>
<file src="src/Internal/Workflow/ScopeContext.php">
<InternalMethod>
<code>getLayer</code>
<code>getLayer</code>
<code>isCancelled</code>
<code>onAwait</code>
<code>startScope</code>
<code>startScope</code>
</InternalMethod>
<PropertyNotSetInConstructor>
<code>$onRequest</code>
<code>$parent</code>
Expand Down Expand Up @@ -1153,6 +1089,12 @@
<code>$promiseOrValue</code>
<code>$promiseOrValue</code>
</MissingParamType>
<PossiblyInvalidArgument>
<code>$reasons</code>
</PossiblyInvalidArgument>
<TooManyArguments>
<code>$reduce($c, $value, $i++, $total)</code>
</TooManyArguments>
</file>
<file src="src/Worker/ActivityInvocationCache/ActivityInvocationCacheInterface.php">
<MissingParamType>
Expand Down
10 changes: 9 additions & 1 deletion src/Internal/Promise/Reasons.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
final class Reasons extends RuntimeException implements Iterator, ArrayAccess, Countable
{
/**
* @param array<array-key, Traversable> $collection
* @param array<TKey, TValue> $collection
*/
public function __construct(
public array $collection,
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 18 additions & 2 deletions src/Internal/Transport/CompletableResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
use Temporal\Workflow;
use Temporal\Workflow\WorkflowContextInterface;

/**
* @template T of mixed
* @implements CompletableResultInterface<T>
*/
class CompletableResult implements CompletableResultInterface
{
/**
Expand All @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -108,7 +118,7 @@ public function then(
}

/**
* @return PromiseInterface
* @return PromiseInterface<T>
*/
public function promise(): PromiseInterface
{
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/Internal/Workflow/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<mixed>
*/
class Process extends Scope implements ProcessInterface
{
/**
Expand Down
1 change: 1 addition & 0 deletions src/Internal/Workflow/Process/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<mixed>
*/
class Scope implements CancellationScopeInterface
{
Expand Down
10 changes: 6 additions & 4 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -207,7 +208,7 @@ static function (mixed $mapped) use ($i, &$values, &$toResolve, $resolve): void
*
* @psalm-param PromiseReduceCallback $reduce
* @param iterable<int, PromiseInterface|mixed> $promises
* @param callable $reduce
* @param callable(mixed $current, mixed $carry, int $current, positive-int $items): mixed $reduce
* @param mixed $initial
* @return PromiseInterface
*/
Expand Down Expand Up @@ -297,7 +298,7 @@ public static function resolve($promiseOrValue = null): PromiseInterface
* the value of another promise.
*
* @param $promiseOrValue
* @return PromiseInterface
* @return PromiseInterface<never>
*/
public static function reject($promiseOrValue = null): PromiseInterface
{
Expand All @@ -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<PromiseInterface<T>|T> $promisesOrValues
* @return PromiseInterface<T>
*/
public static function race(iterable $promisesOrValues): PromiseInterface
{
Expand Down
4 changes: 4 additions & 0 deletions src/Workflow/CancellationScopeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

use React\Promise\PromiseInterface;

/**
* @template T
* @extends PromiseInterface<T>
*/
interface CancellationScopeInterface extends PromiseInterface
{
/**
Expand Down
4 changes: 4 additions & 0 deletions src/Workflow/ProcessInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

use Temporal\Internal\Repository\Identifiable;

/**
* @template T
* @extends CancellationScopeInterface<T>
*/
interface ProcessInterface extends CancellationScopeInterface, Identifiable
{
/**
Expand Down

0 comments on commit e9b1351

Please sign in to comment.