| Conditions | 3 |
| Paths | 3 |
| Total Lines | 27 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| 1 | <?php |
||
| 29 | public function checkLink($href) |
||
| 30 | { |
||
| 31 | // Skip non-external links |
||
| 32 | if (!preg_match('/^https?[^:]*:\/\//', $href)) { |
||
| 33 | return null; |
||
| 34 | } |
||
| 35 | |||
| 36 | // Check if we have a cached result |
||
| 37 | $cacheKey = md5($href); |
||
| 38 | $result = $this->getCache()->load($cacheKey); |
||
| 39 | if ($result !== false) { |
||
| 40 | return $result; |
||
| 41 | } |
||
| 42 | |||
| 43 | // No cached result so just request |
||
| 44 | $handle = curl_init($href); |
||
| 45 | curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); |
||
| 46 | curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5); |
||
| 47 | curl_setopt($handle, CURLOPT_TIMEOUT, 10); |
||
| 48 | curl_exec($handle); |
||
| 49 | $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); |
||
| 50 | curl_close($handle); |
||
| 51 | |||
| 52 | // Cache result |
||
| 53 | $this->getCache()->save($httpCode, $cacheKey); |
||
| 54 | return $httpCode; |
||
| 55 | } |
||
| 56 | } |
||
| 57 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.