| Conditions | 2 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 5 |
| CRAP Score | 2.2109 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | 12 | public function getRecords(string $host, int $type) : DNSRecords |
|
| 11 | { |
||
| 12 | // A workaround to fix https://bugs.php.net/bug.php?id=73149 |
||
| 13 | /** @psalm-suppress InvalidArgument */ |
||
| 14 | 12 | set_error_handler( |
|
| 15 | 12 | static function (int $errorLevel, string $errorMessage): ?bool { |
|
| 16 | throw new \RuntimeException("Unable to get DNS record for the host: $errorMessage"); |
||
| 17 | } |
||
| 18 | ); |
||
| 19 | try { |
||
| 20 | // Get all MX, A and AAAA DNS records for host |
||
| 21 | 12 | return new DNSRecords(dns_get_record($host, $type)); |
|
| 22 | } catch (\RuntimeException $exception) { |
||
| 23 | return new DNSRecords([], true); |
||
| 24 | } finally { |
||
| 25 | 12 | restore_error_handler(); |
|
| 26 | } |
||
| 28 | } |