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

Resolver   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 88.89%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 7
c 4
b 0
f 0
lcom 1
cbo 0
dl 0
loc 39
ccs 16
cts 18
cp 0.8889
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A clear() 0 9 2
B resolve() 0 19 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
}