| 1 | <?php  | 
            ||
| 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 | 8 | public function __construct(int $id)  | 
            |
| 41 | |||
| 42 | /**  | 
            ||
| 43 | * String representation of candidates  | 
            ||
| 44 | *  | 
            ||
| 45 | * @return string  | 
            ||
| 46 | */  | 
            ||
| 47 | public function __toString()  | 
            ||
| 51 | |||
| 52 | /**  | 
            ||
| 53 | * Gets the Identifier for the candidate.  | 
            ||
| 54 | *  | 
            ||
| 55 | * @return int  | 
            ||
| 56 | */  | 
            ||
| 57 | 3 | public function getId(): int  | 
            |
| 61 | |||
| 62 | /**  | 
            ||
| 63 | * Gets the Number of votes the candidate currently has.  | 
            ||
| 64 | *  | 
            ||
| 65 | * @return float  | 
            ||
| 66 | */  | 
            ||
| 67 | 2 | public function getVotes(): float  | 
            |
| 71 | |||
| 72 | /**  | 
            ||
| 73 | * Adds votes to a candidate.  | 
            ||
| 74 | *  | 
            ||
| 75 | * @param float $votes Number of votes to add  | 
            ||
| 76 | *  | 
            ||
| 77 | * @return self  | 
            ||
| 78 | */  | 
            ||
| 79 | 1 | public function addVotes(float $votes)  | 
            |
| 85 | |||
| 86 | /**  | 
            ||
| 87 | * Gets the State of the candidate (use class constants).  | 
            ||
| 88 | *  | 
            ||
| 89 | * @return int  | 
            ||
| 90 | */  | 
            ||
| 91 | 5 | public function getState(): int  | 
            |
| 95 | |||
| 96 | /**  | 
            ||
| 97 | * Sets the State of the candidate (use class constants).  | 
            ||
| 98 | *  | 
            ||
| 99 | * @param int $state the state  | 
            ||
| 100 | *  | 
            ||
| 101 | * @return self  | 
            ||
| 102 | */  | 
            ||
| 103 | 3 | public function setState(int $state)  | 
            |
| 109 | }  | 
            ||
| 110 |