DomainKeyReaderService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDomainKey() 0 18 3
A __construct() 0 3 1
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 DomainKeyReaderService
16
{
17
    private DNSResolver $resolver;
18
19
    public function __construct(DNSResolver $resolver)
20
    {
21
        $this->resolver = $resolver;
22
    }
23
24
    /**
25
     * @throws DomainKeyNotFoundException
26
     */
27
    public function getDomainKey(string $domain, string $selector): array
28
    {
29
        $dkimDomain = \sprintf('%s._domainkey.%s', $selector, $domain);
30
        $result = $this->resolver->resolve($dkimDomain);
31
32
        if (isset($result[0]['entries'])) {
33
            $result[0]['txt'] = implode('', $result[0]['entries']);
34
        }
35
36
        $parts = explode(';', trim($result[0]['txt']));
37
        $record = [];
38
39
        foreach ($parts as $part) {
40
            [$key, $val] = explode('=', trim($part), 2);
41
            $record[$key] = $val;
42
        }
43
44
        return $record;
45
    }
46
}
47