Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| TelegramFetcher | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| callTelegramApi | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Fetchers; |
| 4 | |
| 5 | class TelegramFetcher { |
| 6 | /** |
| 7 | * @param array<string, mixed> $args |
| 8 | * |
| 9 | * @return ?array<string, mixed> |
| 10 | */ |
| 11 | public function callTelegramApi(string $command, array $args, string $bot_token): ?array { |
| 12 | $telegram_url = "https://api.telegram.org/bot{$bot_token}/{$command}"; |
| 13 | |
| 14 | $ch = curl_init(); |
| 15 | curl_setopt($ch, CURLOPT_URL, $telegram_url); |
| 16 | curl_setopt($ch, CURLOPT_POST, true); |
| 17 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($args, '', '&')); |
| 18 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 19 | $telegram_result = curl_exec($ch); |
| 20 | $telegram_response = json_decode(!is_bool($telegram_result) ? $telegram_result : '', true); |
| 21 | curl_close($ch); |
| 22 | |
| 23 | return $telegram_response; |
| 24 | } |
| 25 | } |