Skip to content

Commit

Permalink
Fix psalm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Oct 7, 2024
1 parent ffd3e08 commit 8bc30d2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 71 deletions.
41 changes: 0 additions & 41 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,43 +212,14 @@
<code><![CDATA[$name]]></code>
<code><![CDATA[$value]]></code>
</InvalidArgument>
<MismatchingDocblockParamType>
<code><![CDATA[iterable<array-key, Payload>]]></code>
</MismatchingDocblockParamType>
<MismatchingDocblockReturnType>
<code><![CDATA[EncodedCollection]]></code>
</MismatchingDocblockReturnType>
<MoreSpecificImplementedParamType>
<code><![CDATA[$type]]></code>
</MoreSpecificImplementedParamType>
<PossiblyNullReference>
<code><![CDATA[fromPayload]]></code>
</PossiblyNullReference>
<UnsafeInstantiation>
<code><![CDATA[new static()]]></code>
<code><![CDATA[new static()]]></code>
</UnsafeInstantiation>
</file>
<file src="src/DataConverter/EncodedValues.php">
<InvalidNullableReturnType>
<code><![CDATA[array]]></code>
</InvalidNullableReturnType>
<MissingClosureParamType>
<code><![CDATA[$value]]></code>
</MissingClosureParamType>
<NullableReturnStatement>
<code><![CDATA[$result]]></code>
<code><![CDATA[$result]]></code>
</NullableReturnStatement>
<PossiblyNullArrayAccess>
<code><![CDATA[$this->payloads[$index]]]></code>
</PossiblyNullArrayAccess>
<PossiblyNullIterator>
<code><![CDATA[$this->values]]></code>
</PossiblyNullIterator>
<PossiblyNullReference>
<code><![CDATA[$this->payloads]]></code>
</PossiblyNullReference>
<UnsafeInstantiation>
<code><![CDATA[new static()]]></code>
<code><![CDATA[new static()]]></code>
Expand Down Expand Up @@ -694,12 +665,6 @@
<InvalidFalsableReturnType>
<code><![CDATA[\DateTimeImmutable]]></code>
</InvalidFalsableReturnType>
<InvalidReturnStatement>
<code><![CDATA[\Temporal\Interceptor\Header::fromPayloadCollection($input->getFields(), $this->converter)]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[HeaderInterface]]></code>
</InvalidReturnType>
<LessSpecificReturnStatement>
<code><![CDATA[$mapper]]></code>
</LessSpecificReturnStatement>
Expand Down Expand Up @@ -1306,9 +1271,6 @@
</PossiblyInvalidArgument>
</file>
<file src="src/Worker/Transport/Codec/JsonCodec/Decoder.php">
<InvalidArgument>
<code><![CDATA[Header::fromPayloadCollection($headers->getFields(), $this->dataConverter)]]></code>
</InvalidArgument>
<InvalidReturnStatement>
<code><![CDATA[match (true) {
isset($command['command']) => $this->parseRequest($command, $info),
Expand Down Expand Up @@ -1344,9 +1306,6 @@
<ArgumentTypeCoercion>
<code><![CDATA[$msg->getCommand()]]></code>
</ArgumentTypeCoercion>
<InvalidArgument>
<code><![CDATA[$header]]></code>
</InvalidArgument>
<PossiblyNullArgument>
<code><![CDATA[$msg->getFailure()]]></code>
<code><![CDATA[$msg->getPayloads()]]></code>
Expand Down
44 changes: 15 additions & 29 deletions src/DataConverter/EncodedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<TKey, TValue>&\Countable
*
* @implements IteratorAggregate<TKey, TValue>
* @implements \IteratorAggregate<TKey, TValue>
*/
class EncodedCollection implements \IteratorAggregate, \Countable
{
Expand All @@ -36,16 +34,14 @@ class EncodedCollection implements \IteratorAggregate, \Countable
*/
private ?\ArrayAccess $payloads = null;

/** @var array<TKey, TValue> */
private array $values = [];

/**
* Cannot be constructed directly.
*/
private function __construct() {}
final private function __construct() {}

/**
* @return static
*/
public static function empty(): static
{
$ev = new static();
Expand All @@ -55,10 +51,7 @@ public static function empty(): static
}

/**
* @param iterable $values
* @param DataConverterInterface|null $dataConverter
*
* @return static
* @param iterable<TKey, TValue> $values
*/
public static function fromValues(iterable $values, ?DataConverterInterface $dataConverter = null): static
{
Expand All @@ -72,10 +65,7 @@ public static function fromValues(iterable $values, ?DataConverterInterface $dat
}

/**
* @param iterable<array-key, Payload> $payloads
* @param DataConverterInterface $dataConverter
*
* @return EncodedCollection
* @param array<TKey, Payload>|TPayloadsCollection $payloads
*/
public static function fromPayloadCollection(
array|\ArrayAccess $payloads,
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/DataConverter/EncodedValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8bc30d2

Please sign in to comment.