DNSGetRecordWrapper::getRecords()   A
last analyzed

Complexity

Conditions 2
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.1481

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 16
ccs 6
cts 9
cp 0.6667
crap 2.1481
rs 9.9666
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