Completed
Push — master ( df80f0...840f28 )
by Rafal
11s
created

UserScore   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 90
rs 10
c 0
b 0
f 0
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getCountNoWinTeam() 0 3 1
A getUser() 0 3 1
A getCountWinTeam() 0 3 1
A addScore() 0 4 1
A getScoreSumme() 0 3 1
A getCountWinExact() 0 3 1
A checkPoint() 0 10 2
A getCountWinScoreDiff() 0 3 1
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);
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_sum($this->score) could return the type double which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
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
}