1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace App\GameRating\Business\UserPoint\Info; |
4
|
|
|
|
5
|
|
|
use App\GameBetting\Business\GamePoints\Config; |
6
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
7
|
|
|
|
8
|
|
|
class UserScore |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var array |
12
|
|
|
*/ |
13
|
|
|
private $score = []; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var int |
17
|
|
|
*/ |
18
|
|
|
private $extraScore = 0; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var UserInterface $user |
22
|
|
|
*/ |
23
|
|
|
private $user; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param UserInterface $user |
27
|
|
|
*/ |
28
|
|
|
public function __construct(UserInterface $user) |
29
|
|
|
{ |
30
|
|
|
$this->user = $user; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return UserInterface |
35
|
|
|
*/ |
36
|
|
|
public function getUser(): UserInterface |
37
|
|
|
{ |
38
|
|
|
return $this->user; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param int $scorePoint |
43
|
|
|
*/ |
44
|
|
|
public function addScore(int $scorePoint): void |
45
|
|
|
{ |
46
|
|
|
$this->checkPoint($scorePoint); |
47
|
|
|
$this->score[] = $scorePoint; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param int $extraScore |
52
|
|
|
*/ |
53
|
|
|
public function setExtraScore(int $extraScore): void |
54
|
|
|
{ |
55
|
|
|
$this->extraScore = $extraScore; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return int |
60
|
|
|
*/ |
61
|
|
|
public function getScoreSumme(): int |
62
|
|
|
{ |
63
|
|
|
return array_sum($this->score) + $this->getExtraScore(); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return int |
68
|
|
|
*/ |
69
|
|
|
public function getCountWinExact(): int |
70
|
|
|
{ |
71
|
|
|
return \count(array_keys($this->score, Config::WIN_EXACT)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return int |
76
|
|
|
*/ |
77
|
|
|
public function getCountWinScoreDiff(): int |
78
|
|
|
{ |
79
|
|
|
return \count(array_keys($this->score, Config::WIN_SCORE_DIFF)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return int |
84
|
|
|
*/ |
85
|
|
|
public function getCountWinTeam(): int |
86
|
|
|
{ |
87
|
|
|
return \count(array_keys($this->score, Config::WIN_TEAM)); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return int |
92
|
|
|
*/ |
93
|
|
|
public function getCountNoWinTeam(): int |
94
|
|
|
{ |
95
|
|
|
return \count(array_keys($this->score, Config::NO_WIN_TEAM)); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return int |
100
|
|
|
*/ |
101
|
|
|
public function getExtraScore(): int |
102
|
|
|
{ |
103
|
|
|
return $this->extraScore; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param int $point |
108
|
|
|
*/ |
109
|
|
|
private function checkPoint(int $point) |
110
|
|
|
{ |
111
|
|
|
$allowedPoints = [ |
112
|
|
|
Config::WIN_EXACT => true, |
113
|
|
|
Config::WIN_SCORE_DIFF => true, |
114
|
|
|
Config::WIN_TEAM => true, |
115
|
|
|
Config::NO_WIN_TEAM => true, |
116
|
|
|
]; |
117
|
|
|
if (!isset($allowedPoints[$point])) { |
118
|
|
|
throw new \RuntimeException('Point: ' . $point . ' is not allowed'); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
} |