Ping   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isValidUrl() 0 3 1
A isValidIp() 0 3 1
A ping() 0 29 4
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