Completed
Push — master ( 3a37c9...90ceec )
by Michael
04:14
created

Candidate::setState()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
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 integer
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
	 * Number of surplus votes the candidate has to be re-allocated
27
	 *
28
	 * @var float
29
	 */
30
	protected $surplus;
31
32
	/**
33
	 * State of the candidate (use class constants)
34
	 *
35
	 * @var integer
36
	 */
37
	protected $state;
38
39
	/**
40
	 * Constructor
41
	 */
42 2
	public function __construct(int $id)
43
	{
44 2
		$this->id = $id;
45 2
		$this->votes = 0.0;
46 2
		$this->surplus = 0.0;
47 2
		$this->state = self::RUNNING;
48 2
	}
49
50
    /**
51
     * Gets the Identifier for the candidate.
52
     *
53
     * @return integer
54
     */
55 1
    public function getId(): int
56
    {
57 1
        return $this->id;
58
    }
59
60
    /**
61
     * Gets the Number of votes the candidate currently has.
62
     *
63
     * @return float
64
     */
65 1
    public function getVotes(): float
66
    {
67 1
        return $this->votes;
68
    }
69
70
    /**
71
     * Sets the Number of votes the candidate currently has.
72
     *
73
     * @param float $votes the votes
74
     *
75
     * @return self
76
     */
77
    protected function setVotes(float $votes)
78
    {
79
        $this->votes = $votes;
80
81
        return $this;
82
    }
83
84
    /**
85
     * Gets the Number of surplus votes the candidate has to be re-allocated.
86
     *
87
     * @return float
88
     */
89 1
    public function getSurplus(): float
90
    {
91 1
        return $this->surplus;
92
    }
93
94
    /**
95
     * Sets the Number of surplus votes the candidate has to be re-allocated.
96
     *
97
     * @param float $surplus the surplus
98
     *
99
     * @return self
100
     */
101
    protected function setSurplus(float $surplus)
102
    {
103
        $this->surplus = $surplus;
104
105
        return $this;
106
    }
107
108
    /**
109
     * Gets the State of the candidate (use class constants).
110
     *
111
     * @return integer
112
     */
113 2
    public function getState(): int
114
    {
115 2
        return $this->state;
116
    }
117
118
    /**
119
     * Sets the State of the candidate (use class constants).
120
     *
121
     * @param integer $state the state
122
     *
123
     * @return self
124
     */
125
    protected function setState(int $state)
126
    {
127
        $this->state = $state;
128
129
        return $this;
130
    }
131
}
132