-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTurnstile.php
More file actions
74 lines (65 loc) · 1.01 KB
/
Turnstile.php
File metadata and controls
74 lines (65 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* Turnstile that allows you to pass after you insert a coin
*/
class Turnstile
{
/**
* @var bool lock state
*/
protected $isLocked = true;
/**
* @var bool alarm state
*/
protected $isAlarmRinging = false;
/**
* Accepts a coin from somebody willing to pass
*/
public function acceptCoin()
{
$this->isLocked = false;
$this->shutAlarm();
}
/**
* Turns the turnstile attempting to pass
*/
public function turn()
{
if ($this->isLocked) {
$this->raiseAlarm();
}
else {
$this->isLocked = true;
}
}
/**
* Gets lock state
* @return bool is the turnstile locked
*/
public function getIsLocked()
{
return $this->isLocked;
}
/**
* Gets alarm state
* @return bool is alarm ringing now
*/
public function getIsAlarmRinging()
{
return $this->isAlarmRinging;
}
/**
* Raises alarm
*/
protected function raiseAlarm()
{
$this->isAlarmRinging = true;
}
/**
* Shuts alarm off
*/
protected function shutAlarm()
{
$this->isAlarmRinging = false;
}
}