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

contributte / gosms / 3758550781

pending completion
3758550781

push

github

Milan Felix Ć ulc
DI: little improvements

11 of 11 new or added lines in 1 file covered. (100.0%)

88 of 133 relevant lines covered (66.17%)

0.66 hits per line

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

35.71
/src/Client/AbstractClient.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Gosms\Client;
4

5
use Contributte\Gosms\Auth\IAccessTokenProvider;
6
use Contributte\Gosms\Config;
7
use Contributte\Gosms\Exception\ClientException;
8
use Contributte\Gosms\Http\IHttpClient;
9
use Nette\Utils\Json;
10
use Psr\Http\Message\RequestInterface;
11
use Psr\Http\Message\ResponseInterface;
12
use stdClass;
13

14
abstract class AbstractClient
15
{
16

17
        protected const BASE_URL = Config::URL . '/api/v1';
18

19
        private Config $config;
20

21
        private IHttpClient $client;
22

23
        private IAccessTokenProvider $accessTokenProvider;
24

25
        public function __construct(Config $config, IHttpClient $client, IAccessTokenProvider $accessTokenProvider)
1✔
26
        {
27
                $this->client = $client;
1✔
28
                $this->config = $config;
1✔
29
                $this->accessTokenProvider = $accessTokenProvider;
1✔
30
        }
1✔
31

32
        protected function doRequest(RequestInterface $request): ResponseInterface
33
        {
34
                $token = $this->accessTokenProvider->getAccessToken($this->config);
×
35
                $request = $request->withHeader('Authorization', 'Bearer ' . $token->getAccessToken());
×
36

37
                return $this->client->sendRequest($request);
×
38
        }
39

40
        protected function assertResponse(ResponseInterface $response, int $code = 200): void
41
        {
42
                if ($response->getStatusCode() !== $code) {
×
43
                        throw new ClientException($response->getBody()->getContents(), $response->getStatusCode());
×
44
                }
45
        }
46

47
        protected function decodeResponse(ResponseInterface $response, int $code = 200): stdClass
48
        {
49
                $this->assertResponse($response, $code);
×
50

51
                $data = Json::decode($response->getBody()->getContents());
×
52
                assert($data instanceof stdClass);
×
53

54
                return $data;
×
55
        }
56

57
}
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