| Conditions | 2 |
| Paths | 2 |
| Total Lines | 19 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 5 |
| CRAP Score | 2.7938 |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | 1 | public function get(string $url) |
|
| 16 | { |
||
| 17 | 1 | $cache = $this->cache; |
|
| 18 | |||
| 19 | 1 | $cleanUrl = preg_replace('/[^A-Za-z0-9\-]/', '', $url); |
|
| 20 | |||
| 21 | 1 | if ($cache->get($cleanUrl)) { |
|
| 22 | 1 | return json_decode($cache->get($cleanUrl)); |
|
| 23 | } |
||
| 24 | |||
| 25 | $ch = curl_init(); |
||
| 26 | curl_setopt($ch, CURLOPT_URL, $url); |
||
| 27 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
| 28 | $res = curl_exec($ch); |
||
| 29 | curl_close($ch); |
||
| 30 | |||
| 31 | $cache->set($cleanUrl, $res); |
||
| 32 | |||
| 33 | return json_decode($res); |
||
| 34 | } |
||
| 63 |