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

Resolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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
}