Completed
Pull Request — master (#21)
by Rafal
07:07
created

UserScore::getExtraScore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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();
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_sum($this->... $this->getExtraScore() returns the type double which is incompatible with the type-hinted return integer.
Loading history...
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
}