GoogleDNS   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
c 1
b 0
f 0
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A toDNSRecord() 0 18 5
1
<?php
2
3
namespace RemotelyLiving\PHPDNS\Mappers;
4
5
use RemotelyLiving\PHPDNS\Entities\DNSRecord;
6
use RemotelyLiving\PHPDNS\Entities\DNSRecordType;
7
use RemotelyLiving\PHPDNS\Entities\Hostname;
8
use RemotelyLiving\PHPDNS\Entities\Interfaces\DNSRecordInterface;
9
use RemotelyLiving\PHPDNS\Entities\IPAddress;
10
11
use function str_ireplace;
12
13
final class GoogleDNS extends MapperAbstract
14
{
15
    /**
16
     * @var string
17
     */
18
    private const DATA = 'data';
19
    public function toDNSRecord(): DNSRecordInterface
20
    {
21
        $type = DNSRecordType::createFromInt((int) $this->fields['type']);
22
        $IPAddress = (isset($this->fields[self::DATA]) && IPAddress::isValid($this->fields[self::DATA]))
23
            ? $this->fields[self::DATA]
24
            : null;
25
26
        $value = (isset($this->fields[self::DATA]) && !$IPAddress)
27
            ? str_ireplace('"', '', (string)$this->fields[self::DATA])
28
            : null;
29
30
        return DNSRecord::createFromPrimitives(
31
            (string)$type,
32
            $this->fields['name'],
33
            $this->fields['TTL'],
34
            $IPAddress,
35
            'IN',
36
            $value
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type array; however, parameter $data of RemotelyLiving\PHPDNS\En...:createFromPrimitives() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
            /** @scrutinizer ignore-type */ $value
Loading history...
37
        );
38
    }
39
}
40