Merge branch 'master' into sync/api-schema-0.0.33

This commit is contained in:
Alex
2026-10-01 10:32:49 +03:00
committed by GitHub
3 changed files with 108 additions and 2 deletions
+11 -2
View File
@@ -458,14 +458,23 @@ readonly class ModelFactory
/**
* Creates a specific Update model based on the 'update_type' field.
*
* @param array<string, mixed> $data Raw data for a single update.
* @param mixed $data Raw data for a single update. Anything that is not an array
* (e.g. a scalar produced by json_decode) is converted to LogicException,
* so a webhook or a long-polling loop can skip it instead of crashing.
*
* @return AbstractUpdate
* @throws ReflectionException
* @throws LogicException
*/
public function createUpdate(array $data): AbstractUpdate
public function createUpdate(mixed $data): AbstractUpdate
{
if (!is_array($data)) {
$message = sprintf('Failed to parse update: expected JSON object, got %s', get_debug_type($data));
$this->logger->warning($message, ['payload' => $data]);
throw new LogicException($message);
}
try {
return match (UpdateType::tryFrom($data['update_type'] ?? '')) {
UpdateType::MessageCreated => MessageCreatedUpdate::fromArray($data),