Resolver::resolve()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 8.8571
cc 5
eloc 10
nc 4
nop 2
crap 5
1
<?php
2
namespace Redbox\DNS;
3
4
class Resolver extends \ArrayIterator
5
{
6
7
    /**
8
     * Clear the array
9
     */
10 16
    public function clear()
11
    {
12 16
        $this->rewind();
13 16
        $num = $this->count();
14
15 16
        for ($i = 0; $i < $num; $i++) {
16 4
            $this->offsetUnset($i);
17 4
        }
18 16
    }
19
20
    /**
21
     * @param string $domain
22
     * @param int $type
23
     * @return bool
24
     */
25 16
    public function resolve($domain = '', $type = DNS_ANY)
26
    {
27 16
        if (empty($domain))
28 16
            return false;
29
30 12
        $this->clear();
31
32 12
        $result = dns_get_record($domain, $type);
33
34 12
        if (empty($result) === true || $result === false) {
35 4
            return false;
36
        }
37
38 8
        foreach ($result as $record) {
39 8
            $this->append($record);
40 8
        }
41
42 8
        return true;
43
    }
44
}