Hostname   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 4 1
B hostnameAnalyzer() 0 17 6
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