Completed
Push — master ( e9c488...51c555 )
by Tyler
02:35
created

Host::getStatusCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Tylercd100\ServerStatus;
4
5
use JJG\Ping;
6
use GuzzleHttp\Client;
7
8
class Host 
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $host;
14
15
    /**
16
     * @var Ping
17
     */    
18
    protected $pinger;
19
20
    /**
21
     * @var double
22
     */    
23
    protected $ping = 0.0;
24
25
    /**
26
     * @var integer
27
     */    
28
    protected $statusCode = 0;
29
30
    /**
31
     * @param string $host The host URL or IP to check
32
     */
33 15
    public function __construct($host)
34
    {
35 15
        $this->host = $host;
36 15
        $this->pinger = new Ping($host);
37 15
    }
38
39
    /**
40
     * Checks the ping of the host
41
     * 
42
     * @return double|false
43
     */
44 3
    public function ping(){
45 3
        $this->ping = $this->pinger->ping();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->pinger->ping() can also be of type false. However, the property $ping is declared as type double. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
46 3
        return $this->getPing();
47
    }
48
49
    /**
50
     * Checks the status of the host
51
     * 
52
     * @return integer
53
     */
54
    public function status(){
55
        $client = new Client();
56
        $res = $client->request('GET', $this->host);
57
        $this->statusCode = $res->getStatusCode();
58
        return $this->getStatusCode();
59
    }
60
61
    /**
62
     * Sets the value of pinger.
63
     *
64
     * @return void
65
     */
66 3
    public function setPinger(Ping $pinger)
67
    {
68 3
        $this->pinger = $pinger;
69 3
    }
70
71
    /**
72
     * Gets the value of host.
73
     *
74
     * @return mixed
75
     */
76 3
    public function getHost()
77
    {
78 3
        return $this->host;
79
    }
80
81
    /**
82
     * Gets the value of ping.
83
     *
84
     * @return mixed
85
     */
86 6
    public function getPing()
87
    {
88 6
        return $this->ping;
89
    }
90
91
    /**
92
     * Gets the value of statusCode.
93
     *
94
     * @return mixed
95
     */
96 3
    public function getStatusCode()
97
    {
98 3
        return $this->statusCode;
99
    }
100
}