Completed
Push — master ( 3e7109...ce3c79 )
by Michael
03:47
created

Candidate::setState()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Michaelc\Voting\STV;
4
5
class Candidate
6
{
7
    const ELECTED = 1;
8
    const RUNNING = 2;
9
    const DEFEATED = 3;
10
11
    /**
12
     * Identifier for the candidate.
13
     *
14
     * @var int
15
     */
16
    protected $id;
17
18
    /**
19
     * Number of votes the candidate currently has.
20
     *
21
     * @var float
22
     */
23
    protected $votes;
24
25
    /**
26
     * State of the candidate (use class constants).
27
     *
28
     * @var int
29
     */
30
    protected $state;
31
32
    /**
33
     * Constructor.
34
     */
35 5
    public function __construct(int $id)
36
    {
37 5
        $this->id = $id;
38 5
        $this->votes = 0.0;
39 5
        $this->state = self::RUNNING;
40 5
    }
41
42
    /**
43
     * Gets the Identifier for the candidate.
44
     *
45
     * @return int
46
     */
47 1
    public function getId(): int
48
    {
49 1
        return $this->id;
50
    }
51
52
    /**
53
     * Gets the Number of votes the candidate currently has.
54
     *
55
     * @return float
56
     */
57 2
    public function getVotes(): float
58
    {
59 2
        return $this->votes;
60
    }
61
62
    /**
63
     * Adds votes to a candidate.
64
     *
65
     * @param float $votes Number of votes to add
66
     *
67
     * @return self
68
     */
69 1
    public function addVotes(float $votes)
70
    {
71 1
        $this->votes += $votes;
72
73 1
        return $this;
74
    }
75
76
    /**
77
     * Gets the State of the candidate (use class constants).
78
     *
79
     * @return int
80
     */
81 3
    public function getState(): int
82
    {
83 3
        return $this->state;
84
    }
85
86
    /**
87
     * Sets the State of the candidate (use class constants).
88
     *
89
     * @param int $state the state
90
     *
91
     * @return self
92
     */
93 1
    public function setState(int $state)
94
    {
95 1
        $this->state = $state;
96
97 1
        return $this;
98
    }
99
}
100