Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Curl | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| get | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| getAndWriteToFile | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Projom\Util; |
| 6 | |
| 7 | use Projom\Util\File; |
| 8 | |
| 9 | class Curl |
| 10 | { |
| 11 | const TIME_OUT_SECONDS = 3; |
| 12 | |
| 13 | public static function get(string $url) |
| 14 | { |
| 15 | $handle = curl_init(); |
| 16 | curl_setopt($handle, \CURLOPT_HTTPGET, true); |
| 17 | curl_setopt($handle, \CURLOPT_URL, $url); |
| 18 | curl_setopt($handle, \CURLOPT_HEADER, false); |
| 19 | curl_setopt($handle, \CURLOPT_RETURNTRANSFER, true); |
| 20 | curl_setopt($handle, \CURLOPT_TIMEOUT, static::TIME_OUT_SECONDS); |
| 21 | |
| 22 | $result = curl_exec($handle); |
| 23 | curl_close($handle); |
| 24 | return $result; |
| 25 | } |
| 26 | |
| 27 | public static function getAndWriteToFile(string $url, string $filename): bool |
| 28 | { |
| 29 | if (!$response = static::get($url)) |
| 30 | return false; |
| 31 | |
| 32 | return File::write($filename, $response); |
| 33 | } |
| 34 | } |