|
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 UserInterface $user |
|
17
|
|
|
*/ |
|
18
|
|
|
private $user; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param UserInterface $user |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct(UserInterface $user) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->user = $user; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @return UserInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
public function getUser(): UserInterface |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->user; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param int $scorePoint |
|
38
|
|
|
*/ |
|
39
|
|
|
public function addScore(int $scorePoint): void |
|
40
|
|
|
{ |
|
41
|
|
|
$this->checkPoint($scorePoint); |
|
42
|
|
|
$this->score[] = $scorePoint; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return int |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getScoreSumme(): int |
|
49
|
|
|
{ |
|
50
|
|
|
return array_sum($this->score); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return int |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getCountWinExact(): int |
|
57
|
|
|
{ |
|
58
|
|
|
return \count(array_keys($this->score, Config::WIN_EXACT)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return int |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getCountWinScoreDiff(): int |
|
65
|
|
|
{ |
|
66
|
|
|
return \count(array_keys($this->score, Config::WIN_SCORE_DIFF)); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return int |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getCountWinTeam(): int |
|
73
|
|
|
{ |
|
74
|
|
|
return \count(array_keys($this->score, Config::WIN_TEAM)); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return int |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getCountNoWinTeam(): int |
|
81
|
|
|
{ |
|
82
|
|
|
return \count(array_keys($this->score, Config::NO_WIN_TEAM)); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param int $point |
|
87
|
|
|
*/ |
|
88
|
|
|
private function checkPoint(int $point) |
|
89
|
|
|
{ |
|
90
|
|
|
$allowedPoints = [ |
|
91
|
|
|
Config::WIN_EXACT => true, |
|
92
|
|
|
Config::WIN_SCORE_DIFF => true, |
|
93
|
|
|
Config::WIN_TEAM => true, |
|
94
|
|
|
Config::NO_WIN_TEAM => true, |
|
95
|
|
|
]; |
|
96
|
|
|
if (!isset($allowedPoints[$point])) { |
|
97
|
|
|
throw new \RuntimeException('Point: ' . $point . ' is not allowed'); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
} |