From 8bc30d277d62ecf3aced3b259150c473502df922 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Mon, 7 Oct 2024 12:46:09 +0400 Subject: [PATCH] Fix psalm issues --- psalm-baseline.xml | 41 ----------------------- src/DataConverter/EncodedCollection.php | 44 +++++++++---------------- src/DataConverter/EncodedValues.php | 4 ++- 3 files changed, 18 insertions(+), 71 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 1a1913a2..f3ef0485 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -212,43 +212,14 @@ - - ]]> - - - - - - - - - - - - - - - - - - - - - - - payloads[$index]]]> - values]]> - - payloads]]> - @@ -694,12 +665,6 @@ - - getFields(), $this->converter)]]> - - - - @@ -1306,9 +1271,6 @@ - - getFields(), $this->dataConverter)]]> - $this->parseRequest($command, $info), @@ -1344,9 +1306,6 @@ getCommand()]]> - - - getFailure()]]> getPayloads()]]> diff --git a/src/DataConverter/EncodedCollection.php b/src/DataConverter/EncodedCollection.php index d9c80c92..b245ffd4 100644 --- a/src/DataConverter/EncodedCollection.php +++ b/src/DataConverter/EncodedCollection.php @@ -11,18 +11,16 @@ namespace Temporal\DataConverter; -use ArrayAccess; -use Countable; -use IteratorAggregate; use Temporal\Api\Common\V1\Payload; -use Traversable; /** - * @psalm-type TPayloadsCollection = Traversable&ArrayAccess&Countable + * Assoc collection of typed values. + * * @psalm-type TKey = array-key * @psalm-type TValue = mixed + * @psalm-type TPayloadsCollection = \Traversable&\ArrayAccess&\Countable * - * @implements IteratorAggregate + * @implements \IteratorAggregate */ class EncodedCollection implements \IteratorAggregate, \Countable { @@ -36,16 +34,14 @@ class EncodedCollection implements \IteratorAggregate, \Countable */ private ?\ArrayAccess $payloads = null; + /** @var array */ private array $values = []; /** * Cannot be constructed directly. */ - private function __construct() {} + final private function __construct() {} - /** - * @return static - */ public static function empty(): static { $ev = new static(); @@ -55,10 +51,7 @@ public static function empty(): static } /** - * @param iterable $values - * @param DataConverterInterface|null $dataConverter - * - * @return static + * @param iterable $values */ public static function fromValues(iterable $values, ?DataConverterInterface $dataConverter = null): static { @@ -72,10 +65,7 @@ public static function fromValues(iterable $values, ?DataConverterInterface $dat } /** - * @param iterable $payloads - * @param DataConverterInterface $dataConverter - * - * @return EncodedCollection + * @param array|TPayloadsCollection $payloads */ public static function fromPayloadCollection( array|\ArrayAccess $payloads, @@ -103,8 +93,6 @@ public function isEmpty(): bool /** * @param array-key $name * @param Type|string|null $type - * - * @return mixed */ public function getValue(int|string $name, mixed $type = null): mixed { @@ -143,9 +131,8 @@ public function getValues(): array public function getIterator(): \Traversable { yield from $this->values; - if ($this->payloads !== null) { - $this->converter !== null or $this->payloads->count() === 0 - or throw new \LogicException('DataConverter is not set.'); + if ($this->payloads !== null && $this->payloads->count() > 0) { + $this->converter === null and throw new \LogicException('DataConverter is not set.'); foreach ($this->payloads as $key => $payload) { yield $key => $this->converter->fromPayload($payload, null); @@ -166,9 +153,7 @@ public function toPayloadArray(): array return $data; } - if ($this->converter === null) { - throw new \LogicException('DataConverter is not set.'); - } + $this->converter === null and throw new \LogicException('DataConverter is not set.'); foreach ($this->values as $key => $value) { $data[$key] = $this->converter->toPayload($value); @@ -177,6 +162,10 @@ public function toPayloadArray(): array return $data; } + /** + * @param TKey $name + * @param TValue $value + */ public function withValue(int|string $name, mixed $value): static { $clone = clone $this; @@ -193,9 +182,6 @@ public function withValue(int|string $name, mixed $value): static return $clone; } - /** - * @param DataConverterInterface $converter - */ public function setDataConverter(DataConverterInterface $converter): void { $this->converter = $converter; diff --git a/src/DataConverter/EncodedValues.php b/src/DataConverter/EncodedValues.php index f149d0fc..f1166218 100644 --- a/src/DataConverter/EncodedValues.php +++ b/src/DataConverter/EncodedValues.php @@ -20,8 +20,10 @@ use Traversable; /** + * List of typed values. + * * @psalm-type TPayloadsCollection = Traversable&ArrayAccess&Countable - * @psalm-type TKey = array-key + * @psalm-type TKey = int * @psalm-type TValue = string */ class EncodedValues implements ValuesInterface