1 | <?php |
||
17 | class Candidate |
||
18 | { |
||
19 | use Linkable, CondorcetVersion; |
||
20 | |||
21 | private $_name = []; |
||
22 | private $_provisional = false; |
||
23 | |||
24 | /// |
||
25 | |||
26 | 88 | public function __construct (string $name) |
|
30 | |||
31 | 85 | public function __toString () : string |
|
35 | |||
36 | /// |
||
37 | |||
38 | // SETTERS |
||
39 | |||
40 | 88 | public function setName (string $name) : bool |
|
41 | { |
||
42 | 88 | $name = trim($name); |
|
43 | |||
44 | 88 | if (mb_strlen($name) > Election::MAX_LENGTH_CANDIDATE_ID ) : |
|
45 | 1 | throw new CondorcetException(1, $name); |
|
46 | endif; |
||
47 | |||
48 | 88 | if (!$this->checkName($name)) : |
|
49 | 1 | throw new CondorcetException(19, $name); |
|
50 | endif; |
||
51 | |||
52 | 88 | $this->_name[] = [ 'name' => $name, 'timestamp' => microtime(true) ]; |
|
53 | |||
54 | 88 | return true; |
|
55 | } |
||
56 | |||
57 | 84 | public function setProvisionalState (bool $provisional) : bool |
|
62 | |||
63 | // GETTERS |
||
64 | |||
65 | 86 | public function getName () : string |
|
69 | |||
70 | 3 | public function getHistory () : array |
|
74 | |||
75 | 2 | public function getCreateTimestamp () : float |
|
76 | { |
||
77 | 2 | return $this->_name[0]['timestamp']; |
|
78 | } |
||
79 | |||
80 | 2 | public function getTimestamp () : float |
|
81 | { |
||
82 | 2 | return end($this->_name)['timestamp']; |
|
83 | } |
||
84 | |||
85 | 76 | public function getProvisionalState () : bool |
|
89 | |||
90 | /// |
||
91 | |||
92 | // INTERNAL |
||
93 | |||
94 | 88 | private function checkName (string $name) : bool |
|
104 | } |
||
105 |