Hostname::hostnameAnalyzer()   B
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 12
nc 4
nop 1
1
<?php
2
3
namespace Bouncer\Analyzer;
4
5
class Hostname
6
{
7
8
    public static function load($bouncer)
9
    {
10
        $bouncer->registerAnalyzer('identity', array(__CLASS__, 'hostnameAnalyzer'));
11
    }
12
13
    /*
14
     *
15
     * @param object
16
     *
17
     * @return object
18
     */
19
    public static function hostnameAnalyzer($identity)
20
    {
21
        $address = $identity->getAddress();
22
        if (!$address->getHostname()) {
23
            $hostname = strtolower(gethostbyaddr($address->getValue()));
24
            if ($hostname && $hostname != $address->getValue()) {
25
                $address->setHostname($hostname);
26
                $reverseAddress = gethostbyname($hostname);
27
                if ($reverseAddress && $reverseAddress == $address->getValue()) {
28
                    $address->setAttribute('reverse', true);
29
                } else {
30
                    $address->setAttribute('reverse', false);
31
                }
32
            }
33
        }
34
        return $identity;
35
    }
36
37
}
38