Skip to content

Commit c469339

Browse files
committed
refactor(MediaGroupMessage, PollMessage): Migrate normalizers from configureOptionsResolver
- Refactored MediaGroupMessage and PollMessage classes to introduce a normalizers method. - Replaced configureOptionsResolver method's normalizer definitions with a new normalizers method returning an array of closures. - This change improves code organization and clarity by separating normalization logic from option configuration.
1 parent 3183d96 commit c469339

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/Telegram/Messages/MediaGroupMessage.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ public function toHttpUri(): string
6262
return 'bot{token}/sendMediaGroup';
6363
}
6464

65-
protected function configureOptionsResolver(OptionsResolver $optionsResolver): void
65+
/**
66+
* @return array<string, \Closure(OptionsResolver $optionsResolver, mixed $value): mixed>
67+
*/
68+
protected function normalizers(): array
6669
{
67-
$optionsResolver->setNormalizer(
68-
'media',
69-
static fn (OptionsResolver $_, array $media): string => json_encode($media, \JSON_THROW_ON_ERROR),
70-
);
70+
return [
71+
'media' => static fn (OptionsResolver $_, array $media): string => json_encode($media, \JSON_THROW_ON_ERROR),
72+
];
7173
}
7274
}

src/Telegram/Messages/PollMessage.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,16 @@ public function toHttpUri(): string
8989
protected function configureOptionsResolver(OptionsResolver $optionsResolver): void
9090
{
9191
$optionsResolver
92-
->setAllowedTypes('options', 'array')
93-
->setNormalizer(
94-
'options',
95-
static fn (OptionsResolver $_, array $value): string => json_encode($value, \JSON_THROW_ON_ERROR),
96-
);
92+
->setAllowedTypes('options', 'array');
93+
}
94+
95+
/**
96+
* @return array<string, \Closure(OptionsResolver $optionsResolver, mixed $value): mixed>
97+
*/
98+
protected function normalizers(): array
99+
{
100+
return [
101+
'options' => static fn (OptionsResolver $_, array $value): string => json_encode($value, \JSON_THROW_ON_ERROR),
102+
];
97103
}
98104
}

0 commit comments

Comments
 (0)