Completed
Push — master ( f49e02...f705ca )
by Johnny
02:06
created

Resolver::resolve()   B

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 3
Bugs 0 Features 0
Metric Value
c 3
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 12
    public function clear()
8
    {
9 12
        $this->rewind();
10 12
        $num = $this->count();
11
12 12
        for ($i = 0; $i < $num; $i++) {
13
            $this->offsetUnset($i);
14
        }
15 12
    }
16
17
    /**
18
     * @param string $domain
19
     * @param int $type
20
     * @return bool
21
     */
22 16
    public function resolve($domain = '', $type = DNS_ANY)
23
    {
24 16
        if (empty($domain))
25 16
            return false;
26
27 12
        $this->clear();
28
29 12
        $result = dns_get_record($domain, $type);
30
31 12
        if (empty($result) || $result === false) {
32 4
            return false;
33
        }
34
35 8
        foreach ($result as $record) {
36 8
            $this->append($record);
37 8
        }
38
        
39 8
        return true;
40
    }
41
42
}