• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vjik / telegram-bot-api / 18555779747

16 Oct 2025 08:52AM UTC coverage: 99.481% (-0.5%) from 100.0%
18555779747

Pull #167

github

web-flow
Merge fea52bd4d into e5d621537
Pull Request #167: Add webhook response factories

0 of 35 new or added lines in 3 files covered. (0.0%)

6713 of 6748 relevant lines covered (99.48%)

28.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/WebhookResponse/PsrWebhookResponseFactory.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Vjik\TelegramBot\Api\WebhookResponse;
6

7
use Psr\Http\Message\ResponseFactoryInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\StreamFactoryInterface;
10
use Vjik\TelegramBot\Api\MethodInterface;
11

12
use function json_encode;
13

14
/**
15
 * @api
16
 */
17
final readonly class PsrWebhookResponseFactory
18
{
NEW
19
    public function __construct(
×
20
        private ResponseFactoryInterface $responseFactory,
21
        private StreamFactoryInterface $streamFactory,
NEW
22
    ) {}
×
23

24
    /**
25
     * @throws MethodNotSupportedException If method doesn't support sending via a webhook response.
26
     */
NEW
27
    public function byMethod(MethodInterface $method): ResponseInterface
×
28
    {
NEW
29
        return $this->byWebhookResponse(new WebhookResponse($method));
×
30
    }
31

32
    /**
33
     * @throws MethodNotSupportedException If method doesn't support sending via a webhook response.
34
     */
NEW
35
    public function byWebhookResponse(WebhookResponse $webhookResponse): ResponseInterface
×
36
    {
NEW
37
        $body = $this->streamFactory->createStream(
×
NEW
38
            json_encode($webhookResponse->getData(), JSON_THROW_ON_ERROR),
×
NEW
39
        );
×
40

NEW
41
        return $this->responseFactory
×
NEW
42
            ->createResponse()
×
NEW
43
            ->withBody($body)
×
NEW
44
            ->withHeader('Content-Type', 'application/json; charset=utf-8')
×
NEW
45
            ->withHeader('Content-Length', (string) $body->getSize());
×
46
    }
47
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc