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

Ping::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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