DNSGetRecordWrapper   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 24
ccs 7
cts 10
cp 0.7
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRecords() 0 16 2
1
<?php
2
3
namespace Egulias\EmailValidator\Validation;
4
5
class DNSGetRecordWrapper
6
{
7
    /**
8
     * @param string $host
9
     * @param int $type
10 12
     * 
11
     * @return DNSRecords
12
     */
13
    public function getRecords(string $host, int $type): DNSRecords
14 12
    {
15 12
        // A workaround to fix https://bugs.php.net/bug.php?id=73149
16
        /** @psalm-suppress InvalidArgument */
17 12
        set_error_handler(
18 12
            static function (int $errorLevel, string $errorMessage): never {
19
                throw new \RuntimeException("Unable to get DNS record for the host: $errorMessage");
20
            }
21 12
        );
22
        try {
23
            // Get all MX, A and AAAA DNS records for host
24
            return new DNSRecords(dns_get_record($host, $type));
25 12
        } catch (\RuntimeException $exception) {
26
            return new DNSRecords([], true);
27
        } finally {
28
            restore_error_handler();
29
        }
30
    }
31
}
32