Ping::ping()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 29
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 29
rs 9.8333
1
<?php
2
namespace GJClasses;
3
4
class Ping
5
{
6
    public function ping($host)
7
    {
8
        $is_valid_ip = $this->isValidIp($host);
9
10
        if ($is_valid_ip) {
11
12
            exec("ping -n 2 $host", $output, $result);
13
14
            if ($result === 0) {
15
16
                return true;
17
18
            } else {
19
20
                return false;
21
22
            }
23
24
        } else {
25
26
            $result_url = $this->isValidUrl($host);
27
28
            if ($result_url != $host) {
29
30
                return true;
31
32
            } else {
33
34
                return false;
35
36
            }
37
38
        }
39
40
    }
41
42
    public function isValidIp($host)
43
    {
44
        return gethostbyaddr($host);
45
    }
46
47
    public function isValidUrl($host)
48
    {
49
        return gethostbyname($host);
50
    }
51
52
}
53