Skip to content

Commit

Permalink
PHP 8.3: New #[\Override] attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-boudry committed May 28, 2024
1 parent 2b6dbf4 commit 67ef646
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Algo/Methods/Borda/DowdallSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DowdallSystem extends BordaCount
// Method Name
public const array METHOD_NAME = ['DowdallSystem', 'Dowdall System', 'Nauru', 'Borda Nauru'];

#[\Override]
protected function getScoreByCandidateRanking(int $CandidatesRanked, Election $election): float
{
return (float) (1 / ($CandidatesRanked + 1));
Expand Down
1 change: 1 addition & 0 deletions src/Algo/Methods/Copeland/Copeland.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Copeland extends PairwiseStatsBased_Core

//:: COPELAND ALGORITHM. :://

#[\Override]
protected function looking(array $challenge): int
{
return max($challenge);
Expand Down
1 change: 1 addition & 0 deletions src/Algo/Methods/Dodgson/DodgsonTidemanApproximation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class DodgsonTidemanApproximation extends PairwiseStatsBased_Core implements Met

//:: DODGSON ALGORITHM. :://

#[\Override]
protected function looking(array $challenge): int
{
return min($challenge);
Expand Down
1 change: 1 addition & 0 deletions src/Algo/Methods/HighestAverages/Jefferson.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Jefferson extends HighestAverages_Core implements MethodInterface

/////////// COMPUTE ///////////

#[\Override]
protected function computeQuotient(int $votesWeight, int $seats): float
{
return (float) ($votesWeight / ($seats + 1));
Expand Down
1 change: 1 addition & 0 deletions src/Algo/Methods/HighestAverages/SainteLague.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SainteLague extends HighestAverages_Core implements MethodInterface
// Method Name
public const array METHOD_NAME = ['Sainte-Laguë', 'SainteLague', 'Webster', 'Major Fractions Method'];

#[\Override]
protected function computeQuotient(int $votesWeight, int $seats): float
{
$divisor = ($seats !== 0) ? ($seats * 2 + 1) : self::$optionFirstDivisor;
Expand Down
2 changes: 2 additions & 0 deletions src/Algo/Methods/LargestRemainder/LargestRemainder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class LargestRemainder extends HighestAverages_Core implements MethodInterface

public static StvQuotas $optionQuota = StvQuotas::HARE;

#[\Override]
protected function makeRounds(): array
{
$election = $this->getElection();
Expand Down Expand Up @@ -63,6 +64,7 @@ protected function makeRounds(): array
return $results;
}

#[\Override]
protected function computeQuotient(int $votesWeight, int $seats): float
{
return self::$optionQuota->getQuota($votesWeight, $seats);
Expand Down
1 change: 1 addition & 0 deletions src/Algo/Methods/Minimax/MinimaxMargin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MinimaxMargin extends PairwiseStatsBased_Core

//:: SIMPSON ALGORITHM. :://

#[\Override]
protected function looking(array $challenge): int
{
return min($challenge);
Expand Down
1 change: 1 addition & 0 deletions src/Algo/Methods/Minimax/MinimaxOpposition.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MinimaxOpposition extends PairwiseStatsBased_Core

//:: SIMPSON ALGORITHM. :://

#[\Override]
protected function looking(array $challenge): int
{
return min($challenge);
Expand Down
1 change: 1 addition & 0 deletions src/Algo/Methods/Minimax/MinimaxWinning.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MinimaxWinning extends PairwiseStatsBased_Core

//:: SIMPSON ALGORITHM. :://

#[\Override]
protected function looking(array $challenge): int
{
return min($challenge);
Expand Down
1 change: 1 addition & 0 deletions src/Algo/Methods/STV/CPO_STV.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CPO_STV extends SingleTransferableVote

/////////// COMPUTE ///////////

#[\Override]
protected function compute(): void
{
Vote::initCache(); // Performances
Expand Down
1 change: 1 addition & 0 deletions src/Algo/Methods/Schulze/SchulzeMargin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SchulzeMargin extends Schulze_Core
// Method Name
public const array METHOD_NAME = ['Schulze Margin', 'SchulzeMargin', 'Schulze_Margin'];

#[\Override]
protected function schulzeVariant(int $i, int $j, Election $election): int
{
return $election->getPairwise()[$i]['win'][$j] - $election->getPairwise()[$j]['win'][$i];
Expand Down
1 change: 1 addition & 0 deletions src/Algo/Methods/Schulze/SchulzeRatio.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SchulzeRatio extends Schulze_Core
// Method Name
public const array METHOD_NAME = ['Schulze Ratio', 'SchulzeRatio', 'Schulze_Ratio'];

#[\Override]
protected function schulzeVariant(int $i, int $j, Election $election): float
{
if ($election->getPairwise()[$j]['win'][$i] !== 0) {
Expand Down
1 change: 1 addition & 0 deletions src/Algo/Methods/Schulze/SchulzeWinning.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SchulzeWinning extends Schulze_Core
// Method Name
public const array METHOD_NAME = ['Schulze Winning', 'Schulze', 'SchulzeWinning', 'Schulze_Winning', 'Schwartz Sequential Dropping', 'SSD', 'Cloneproof Schwartz Sequential Dropping', 'CSSD', 'Beatpath', 'Beatpath Method', 'Beatpath Winner', 'Path Voting', 'Path Winner'];

#[\Override]
protected function schulzeVariant(int $i, int $j, Election $election): int
{
return $election->getPairwise()[$i]['win'][$j];
Expand Down
2 changes: 2 additions & 0 deletions src/Algo/Pairwise/FilteredPairwise.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ public function __construct(
$this->candidates = $link->getCandidatesListAsString();
}

#[\Override]
protected function getVotesManagerGenerator(): \Generator
{
return $this->getElection()->getVotesManager()->getVotesValidUnderConstraintGenerator(tags: $this->tags, with: $this->withTags);
}

#[\Override]
protected function getCandidateNameFromKey(int $candidateKey): string
{
return $this->candidates[$candidateKey];
Expand Down
6 changes: 6 additions & 0 deletions src/DataManager/VotesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class VotesManager extends ArrayManager
{
/////////// Data CallBack for external drivers ///////////

#[\Override]
protected function decodeOneEntity(string $data): Vote
{
$vote = new Vote($data);
Expand All @@ -33,6 +34,7 @@ protected function decodeOneEntity(string $data): Vote
return $vote;
}

#[\Override]
protected function encodeOneEntity(Vote $data): string
{
if (($election = $this->getElection()) !== null) {
Expand All @@ -42,19 +44,22 @@ protected function encodeOneEntity(Vote $data): string
return str_replace([' > ', ' = '], ['>', '='], (string) $data);
}

#[\Override]
protected function preDeletedTask(Vote $object): void
{
$object->destroyLink($this->getElection());
}

/////////// Array Access - Specials improvements ///////////

#[\Override]
public function offsetGet(mixed $offset): Vote
{
return parent::offsetGet($offset);
}

#[Throws(VoteManagerException::class)]
#[\Override]
public function offsetSet(mixed $offset, mixed $value): void
{
if ($value instanceof Vote) {
Expand All @@ -76,6 +81,7 @@ public function offsetSet(mixed $offset, mixed $value): void
$this->checkRegularize();
}

#[\Override]
public function offsetUnset(mixed $offset): void
{
if ($this->offsetExists($offset)) {
Expand Down
1 change: 1 addition & 0 deletions src/Tools/Converters/CEF/CondorcetElectionFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public function __construct(
#[Description('Add the data to an election object')]
#[FunctionReturn('The election object')]
#[Related("Tools\DavidHillFormat::setDataToAnElection", "Tools\DebianFormat::setDataToAnElection")]
#[\Override]
public function setDataToAnElection(
#[FunctionParameter('Add an existing election, useful if you want to set up some parameters or add extra candidates. If null an election object will be created for you.')]
Election $election = new Election,
Expand Down
1 change: 1 addition & 0 deletions src/Tools/Converters/DavidHillFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function __construct(
#[Description('Add the data to an election object')]
#[FunctionReturn('The election object')]
#[Related("Tools\CondorcetElectionFormat::setDataToAnElection", "Tools\DebianFormat::setDataToAnElection")]
#[\Override]
public function setDataToAnElection(
#[FunctionParameter('Add an existing election, useful if you want to set up some parameters or add extra candidates. If null an election object will be created for you.')]
?Election $election = null
Expand Down
1 change: 1 addition & 0 deletions src/Tools/Converters/DebianFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function __construct(
#[Description('Add the Debian data to an election object')]
#[FunctionReturn('The election object')]
#[Related("Tools\CondorcetElectionFormat::setDataToAnElection", "Tools\DavidHillFormat::setDataToAnElection")]
#[\Override]
public function setDataToAnElection(
#[FunctionParameter('Add an existing election, useful if you want to set up some parameters or add extra candidates. If null an election object will be created for you.')]
?Election $election = null
Expand Down

0 comments on commit 67ef646

Please sign in to comment.