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

Resolver::clear()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0932

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 7
cp 0.7143
rs 9.6666
cc 2
eloc 5
nc 2
nop 0
crap 2.0932
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
}