Passed
Pull Request — 3.x (#323)
by Eduardo Gulias
09:09 queued 07:19
created

DNSGetRecordWrapper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 62.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 22
ccs 5
cts 8
cp 0.625
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRecords() 0 16 2
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
}