Resolver::clear()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

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