NativeDNS   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A checkChallenge() 0 10 5
1
<?php
2
3
namespace Zwartpet\PHPCertificateToolbox\DNSValidator;
4
5
/**
6
 * NativeDNS implements DNSValidatorInterface using locally available DNS services
7
 *
8
 * @package Zwartpet\PHPCertificateToolbox
9
 * @codeCoverageIgnore
10
 */
11
class NativeDNS implements DNSValidatorInterface
12
{
13
    public function checkChallenge($domain, $requiredDigest) : bool
14
    {
15
        $hostname = '_acme-challenge.' . str_replace('*.', '', $domain);
16
        $records =  dns_get_record($hostname, DNS_TXT);
17
        foreach ($records as $record) {
18
            if ($record['host'] == $hostname && $record['type'] == 'TXT' && $record['txt'] == $requiredDigest) {
19
                return true;
20
            }
21
        }
22
        return false;
23
    }
24
}
25