Completed
Push — master ( b2dfe1...1412d2 )
by Sam
02:32
created

InstanceState::isReachable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
namespace Jalle19\StatusManager\Instance;
4
5
/**
6
 * Represents the reachability of an instance.
7
 *
8
 * @package   Jalle19\StatusManager\Instance
9
 * @copyright Copyright &copy; Sam Stenvall 2015-
10
 * @license   https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0
11
 */
12
class InstanceState
13
{
14
15
	const REACHABLE       = 0;
16
	const MAYBE_REACHABLE = 1;
17
	const UNREACHABLE     = 2;
18
19
	/**
20
	 * @var int the number of retries since marked as unreachable
21
	 */
22
	private $_retryCount = 0;
23
24
	/**
25
	 * @var int the instance reachability state
26
	 */
27
	private $_reachability = self::MAYBE_REACHABLE;
28
29
30
	/**
31
	 * Increments the retry counter
32
	 */
33
	public function incrementRetryCount()
34
	{
35
		$this->_retryCount++;
36
	}
37
38
39
	/**
40
	 * @return int the retry count
41
	 */
42
	public function getRetryCount()
43
	{
44
		return $this->_retryCount;
45
	}
46
47
48
	/**
49
	 * Resets the retry count
50
	 */
51
	public function resetRetryCount()
52
	{
53
		$this->_retryCount = 0;
54
	}
55
56
57
	/**
58
	 * @return bool whether the instance is reachable
59
	 */
60
	public function isReachable()
61
	{
62
		return $this->_reachability === self::REACHABLE || $this->_reachability === self::MAYBE_REACHABLE;
63
	}
64
65
66
	/**
67
	 * @return int the instance reachability state
68
	 */
69
	public function getReachability()
70
	{
71
		return $this->_reachability;
72
	}
73
74
75
	/**
76
	 * Sets the reachability state of the instance
77
	 *
78
	 * @param int $reachable one of the reachability states
79
	 */
80
	public function setReachability($reachable)
81
	{
82
		$this->_reachability = $reachable;
83
	}
84
85
}
86