NativeDNS::checkChallenge()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 6
nc 3
nop 2
dl 0
loc 10
rs 9.6111
c 0
b 0
f 0
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