PlayerRound.php
1.86 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace FootyRoom\Core\Predictor;
use FootyRoom\Core\CoreException;
use FootyRoom\Core\Predictor\Player;
use FootyRoom\Core\Predictor\RoundId;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/**
* @ODM\Document(collection="predictor.summaries")
*/
class PlayerRound
{
/**
* @ODM\Id
*
* @var string
*/
protected $id;
/**
* @ODM\Field(type="int")
*
* @var int
*/
protected $userId;
/**
* @ODM\Field(type="string")
*
* @var string
*/
protected $username;
/**
* @ODM\Field(type="string", name="phase")
*
* @var string
*/
protected $roundId;
/**
* @ODM\Field(type="int", strategy="increment")
*
* @var int
*/
protected $stake;
/**
* @ODM\Field(type="int", strategy="increment")
*
* @var int
*/
protected $locked;
/**
* @var int
*/
public const MAX_STAKE_PER_ROUND = 2000;
public function __construct(Player $player, RoundId $roundId)
{
$this->userId = $player->getUserId();
$this->username = $player->getUsername();
$this->roundId = $roundId->getValue();
}
public function getUserId(): int
{
return $this->userId;
}
public function getUsername(): string
{
return $this->username;
}
public function getRoundId(): string
{
return $this->roundId;
}
public function getStake(): int
{
return $this->stake;
}
public function getLocked(): int
{
return $this->locked;
}
public function bet(int $stake = 0)
{
if ($stake + $this->stake > self::MAX_STAKE_PER_ROUND) {
throw new CoreException('You can\'t make this bet because it\'s over your round limit.');
}
$this->stake += $stake;
$this->locked += $stake;
}
}