DNSResolver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 10
c 3
b 0
f 0
dl 0
loc 23
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * This file is part of the mailserver-admin package.
6
 * (c) Jeffrey Boehm <https://github.com/jeboehm/mailserver-admin>
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace App\Service\DKIM;
12
13
use App\Exception\DKIM\DomainKeyNotFoundException;
14
15
class DNSResolver
16
{
17
    /**
18
     * @throws DomainKeyNotFoundException
19
     */
20
    public function resolve(string $address): array
21
    {
22
        $result = @dns_get_record($address, \DNS_TXT);
23
24
        if (!\is_array($result)) {
25
            throw new DomainKeyNotFoundException(\sprintf('Cannot get DNS records for %s', $address));
26
        }
27
28
        $result = \array_filter(
29
            $result,
30
            static fn (array $row) => $row['host'] === $address
31
        );
32
33
        if (0 === \count($result)) {
34
            throw new DomainKeyNotFoundException(\sprintf('txt record for %s was not found', $address));
35
        }
36
37
        return $result;
38
    }
39
}
40