Skip to content

Commit 0a72800

Browse files
committed
Add typed docblocks and asserts.
1 parent b01bee3 commit 0a72800

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎src/Dto/DtoManager.php‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ public static function serialize(array|object $data): array
6262
/**
6363
* Hydrate queue data back into a DTO instance.
6464
*
65+
* @template T of object
6566
* @param array<string, mixed> $data Serialized data.
66-
* @param class-string $dtoClass DTO class name.
67-
* @return object Hydrated DTO instance.
67+
* @param class-string<T> $dtoClass DTO class name.
68+
* @return T Hydrated DTO instance.
6869
* @throws \InvalidArgumentException When the DTO class does not exist.
6970
*/
7071
public static function deserialize(array $data, string $dtoClass): object
@@ -73,7 +74,10 @@ public static function deserialize(array $data, string $dtoClass): object
7374
throw new InvalidArgumentException(sprintf('DTO class `%s` does not exist.', $dtoClass));
7475
}
7576

76-
return (new ResultSetFactory())->hydrateDto($data, $dtoClass);
77+
$dto = (new ResultSetFactory())->hydrateDto($data, $dtoClass);
78+
assert($dto instanceof $dtoClass);
79+
80+
return $dto;
7781
}
7882

7983
/**

‎src/Job/Message.php‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,22 @@ public function getDtoClass(): ?string
186186
public function getDto(string $dtoClass): object
187187
{
188188
if ($this->dto !== null && $this->dtoHydratedAs === $dtoClass) {
189+
assert($this->dto instanceof $dtoClass);
190+
189191
return $this->dto;
190192
}
191193

192194
if (!class_exists($dtoClass)) {
193195
throw new InvalidArgumentException(sprintf('DTO class `%s` does not exist.', $dtoClass));
194196
}
195197

196-
$this->dto = DtoManager::deserialize($this->getArgument(), $dtoClass);
198+
$dto = DtoManager::deserialize($this->getArgument(), $dtoClass);
199+
assert($dto instanceof $dtoClass);
200+
201+
$this->dto = $dto;
197202
$this->dtoHydratedAs = $dtoClass;
198203

199-
return $this->dto;
204+
return $dto;
200205
}
201206

202207
/**

0 commit comments

Comments
 (0)