Passed
Pull Request — 3.x (#323)
by Eduardo Gulias
04:35 queued 02:42
created

DNSGetRecordWrapper::getRecords()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.2109

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 5
cts 8
cp 0.625
crap 2.2109
rs 9.9666
1
<?php
2
namespace Egulias\EmailValidator\Validation;
3
4
class DNSGetRecordWrapper
5
{
6
    /**
7
     * @param string $host
8
     * @param int $type
9
     */
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
        }
27
    }
28
}