Passed
Push — dev ( edc43c...f93733 )
by Greg
02:41
created

Ping   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isValidUrl() 0 3 1
A isValidIp() 0 3 1
A ping() 0 29 4
A __construct() 0 3 1
1
<?php
2
namespace GJClasses;
3
4
class Ping
5
{
6
    public $log;
7
8
    public function __construct()
9
    {
10
        $this->log = new Log('class.ping');
11
    }
12
13
    public function ping($host)
14
    {
15
        $is_valid_ip = $this->isValidIp($host);
16
17
        if ($is_valid_ip) {
18
19
            exec("ping -n 2 $host", $output, $result);
20
21
            if ($result === 0) {
22
23
                return true;
24
25
            } else {
26
27
                return false;
28
29
            }
30
31
        } else {
32
33
            $result_url = $this->isValidUrl($host);
34
35
            if ($result_url != $host) {
36
37
                return true;
38
39
            } else {
40
41
                return false;
42
43
            }
44
45
        }
46
47
    }
48
49
    public function isValidIp($host)
50
    {
51
        return gethostbyaddr($host);
52
    }
53
54
    public function isValidUrl($host)
55
    {
56
        return gethostbyname($host);
57
    }
58
59
}
60