Total Complexity | 6 |
Total Lines | 78 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
11 | class Client |
||
12 | { |
||
13 | const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'; |
||
14 | |||
15 | /** |
||
16 | * @var resource |
||
17 | */ |
||
18 | protected $curl; |
||
19 | |||
20 | /** |
||
21 | * Initializes the cURL session. |
||
22 | */ |
||
23 | 12 | public function __construct() |
|
34 | 12 | } |
|
35 | |||
36 | /** |
||
37 | * Performs the cURL session. |
||
38 | * |
||
39 | * @param boolean $close |
||
40 | * @return mixed |
||
41 | */ |
||
42 | 12 | public function execute($close = true) |
|
43 | { |
||
44 | 12 | $result = curl_exec($this->curl); |
|
45 | |||
46 | 12 | $close && curl_close($this->curl); |
|
47 | |||
48 | 12 | return $result; |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * Sets an option to the cURL session. |
||
53 | * |
||
54 | * @param integer $key |
||
55 | * @param mixed $value |
||
56 | * @return self |
||
57 | */ |
||
58 | 12 | public function set($key, $value) |
|
59 | { |
||
60 | 12 | curl_setopt($this->curl, $key, $value); |
|
61 | |||
62 | 12 | return $this; |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * Sets the URL to be used in the cURL session. |
||
67 | * |
||
68 | * @param string $link |
||
69 | * @return self |
||
70 | */ |
||
71 | 12 | public function url($link) |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * Performs a new cURL session with an URL. |
||
78 | * |
||
79 | * @param string $url |
||
80 | * @return string |
||
81 | */ |
||
82 | 12 | public static function request($url) |
|
91 |