1 | <?php |
||
7 | class VoteHandler |
||
8 | { |
||
9 | /** |
||
10 | * Election object |
||
11 | * |
||
12 | * @var \Michaelc\Voting\STV\Election; |
||
13 | */ |
||
14 | protected $election; |
||
15 | |||
16 | /** |
||
17 | * Array of all ballots in election |
||
18 | * |
||
19 | * @var \MichaelC\Voting\STV\Ballot[] |
||
20 | */ |
||
21 | protected $ballots; |
||
22 | |||
23 | /** |
||
24 | * Quota of votes needed for a candidate to be elected |
||
25 | * |
||
26 | * @var int |
||
27 | */ |
||
28 | protected $quota; |
||
29 | |||
30 | /** |
||
31 | * Constructor |
||
32 | * |
||
33 | * @param Election $election |
||
34 | */ |
||
35 | 1 | public function __construct(Election $election) |
|
41 | |||
42 | public function step($step) |
||
59 | |||
60 | protected function allocateVotes(&$ballot): Ballot |
||
69 | |||
70 | protected function transferVotes(float $votes, Candidate $candidate) |
||
74 | |||
75 | /** |
||
76 | * Elect a candidate after they've passed the threshold |
||
77 | * |
||
78 | * @param \Michaelc\Voting\STV\Candidate $candidate |
||
79 | * @return null |
||
80 | */ |
||
81 | protected function electCandidate(Candidate $candidate) |
||
95 | |||
96 | /** |
||
97 | * Get the quota to win |
||
98 | * |
||
99 | * @return int |
||
100 | */ |
||
101 | 1 | public function getQuota(): int |
|
109 | } |
||
110 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: