Skip to content

Commit bf15ee7

Browse files
committed
Narrow message metadata type to array<string, mixed>
1 parent f3c55b1 commit bf15ee7

5 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/Message/Envelope.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
abstract class Envelope implements EnvelopeInterface
1010
{
11+
/**
12+
* @psalm-var array<string, mixed>|null
13+
*/
1114
private ?array $metadata = null;
1215

1316
public function __construct(protected MessageInterface $message) {}

src/Message/IdEnvelope.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ public function __construct(
2222

2323
public static function fromMessage(MessageInterface $message): static
2424
{
25-
/** @var mixed $rawId */
2625
$rawId = $message->getMetadata()[self::MESSAGE_ID_KEY] ?? null;
2726

28-
/** @var int|string|null $id */
2927
$id = match (true) {
3028
$rawId === null => null, // don't remove this branch: it's important for compute speed
31-
is_string($rawId) => $rawId,
29+
is_string($rawId),
3230
is_int($rawId) => $rawId,
3331
is_object($rawId) && method_exists($rawId, '__toString') => (string) $rawId,
3432
default => null,

src/Message/Message.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ final class Message implements MessageInterface
1010
* @param string $type A message type used to resolve the handler.
1111
* @param mixed $data Message data, encodable by a queue adapter
1212
* @param array $metadata Message metadata, encodable by a queue adapter
13+
*
14+
* @psalm-param array<string, mixed> $metadata
1315
*/
1416
public function __construct(
1517
private readonly string $type,

src/Message/MessageInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public function getType(): string;
1919
public function getData(): mixed;
2020

2121
/**
22-
* Returns message metadata: timings, attempts count, metrics, etc.
22+
* Returns message metadata: timings, attempts count, metrics, etc. Keys are always strings.
23+
*
24+
* @return array<string, mixed>
2325
*/
2426
public function getMetadata(): array;
2527
}

src/Queue.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ public function push(MessageInterface $message): MessageInterface
9696
return $message;
9797
}
9898

99-
/** @var string $messageId */
10099
$messageId = $message->getMetadata()[IdEnvelope::MESSAGE_ID_KEY] ?? 'null';
101100
$this->logger->info(
102101
'Pushed message with message type "{messageType}" to the queue. Assigned ID #{id}.',

0 commit comments

Comments
 (0)