Completed
Push — master ( 903df6...64a9b8 )
by Alexander
18s queued 15s
created

SymfonyHttpClient   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 18
c 1
b 0
f 0
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A doRequest() 0 16 3
A doDownload() 0 6 2
1
<?php
2
3
namespace TelegramBot\Api\Http;
4
5
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Contracts\HttpCl...tion\ExceptionInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Contracts\HttpClient\HttpClientInterface as SymfonyHttpClientInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Contracts\HttpClient\HttpClientInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use TelegramBot\Api\HttpException;
8
9
class SymfonyHttpClient extends AbstractHttpClient
10
{
11
    /**
12
     * @var SymfonyHttpClientInterface
13
     */
14
    private $http;
15
16
    public function __construct(SymfonyHttpClientInterface $http)
17
    {
18
        $this->http = $http;
19
    }
20
21
    /**
22
     * @inheritDoc
23
     */
24
    protected function doRequest($url, array $data = null)
25
    {
26
        $options = [];
27
        if ($data) {
28
            $method = 'POST';
29
            $options['body'] = $data;
30
        } else {
31
            $method = 'GET';
32
        }
33
34
        $response = $this->http->request($method, $url, $options);
35
36
        try {
37
            return $response->toArray();
38
        } catch (ExceptionInterface $exception) {
39
            throw new HttpException($exception->getMessage(), $exception->getCode(), $exception);
40
        }
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46
    protected function doDownload($url)
47
    {
48
        try {
49
            return $this->http->request('GET', $url)->getContent();
50
        } catch (ExceptionInterface $exception) {
51
            throw new HttpException($exception->getMessage(), $exception->getCode(), $exception);
52
        }
53
    }
54
}
55