AbstractHttpClient   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A download() 0 3 1
A request() 0 9 3
1
<?php
2
3
namespace TelegramBot\Api\Http;
4
5
use TelegramBot\Api\Exception;
6
7
abstract class AbstractHttpClient implements HttpClientInterface
8
{
9
    public function request($url, array $data = null)
10
    {
11
        $response = $this->doRequest($url, $data);
12
13
        if (!isset($response['ok']) || !$response['ok']) {
14
            throw new Exception($response['description'], $response['error_code']);
15
        }
16
17
        return $response['result'];
18
    }
19
20
    public function download($url)
21
    {
22
        return $this->doDownload($url);
23
    }
24
25
    /**
26
     * @param string $url
27
     * @param array|null $data
28
     * @return array
29
     */
30
    abstract protected function doRequest($url, array $data = null);
31
32
    /**
33
     * @param string $url
34
     * @return string
35
     */
36
    abstract protected function doDownload($url);
37
}
38