From 67ef64693efc9e9eb8041e2a9482b8514c23a8de Mon Sep 17 00:00:00 2001 From: Julien Boudry Date: Tue, 28 May 2024 19:34:28 +0200 Subject: [PATCH] PHP 8.3: New #[\Override] attribute --- src/Algo/Methods/Borda/DowdallSystem.php | 1 + src/Algo/Methods/Copeland/Copeland.php | 1 + src/Algo/Methods/Dodgson/DodgsonTidemanApproximation.php | 1 + src/Algo/Methods/HighestAverages/Jefferson.php | 1 + src/Algo/Methods/HighestAverages/SainteLague.php | 1 + src/Algo/Methods/LargestRemainder/LargestRemainder.php | 2 ++ src/Algo/Methods/Minimax/MinimaxMargin.php | 1 + src/Algo/Methods/Minimax/MinimaxOpposition.php | 1 + src/Algo/Methods/Minimax/MinimaxWinning.php | 1 + src/Algo/Methods/STV/CPO_STV.php | 1 + src/Algo/Methods/Schulze/SchulzeMargin.php | 1 + src/Algo/Methods/Schulze/SchulzeRatio.php | 1 + src/Algo/Methods/Schulze/SchulzeWinning.php | 1 + src/Algo/Pairwise/FilteredPairwise.php | 2 ++ src/DataManager/VotesManager.php | 6 ++++++ src/Tools/Converters/CEF/CondorcetElectionFormat.php | 1 + src/Tools/Converters/DavidHillFormat.php | 1 + src/Tools/Converters/DebianFormat.php | 1 + 18 files changed, 25 insertions(+) diff --git a/src/Algo/Methods/Borda/DowdallSystem.php b/src/Algo/Methods/Borda/DowdallSystem.php index 2470221b..acdcf4c5 100644 --- a/src/Algo/Methods/Borda/DowdallSystem.php +++ b/src/Algo/Methods/Borda/DowdallSystem.php @@ -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)); diff --git a/src/Algo/Methods/Copeland/Copeland.php b/src/Algo/Methods/Copeland/Copeland.php index b1ba91d1..f7b50612 100644 --- a/src/Algo/Methods/Copeland/Copeland.php +++ b/src/Algo/Methods/Copeland/Copeland.php @@ -28,6 +28,7 @@ class Copeland extends PairwiseStatsBased_Core //:: COPELAND ALGORITHM. ::// + #[\Override] protected function looking(array $challenge): int { return max($challenge); diff --git a/src/Algo/Methods/Dodgson/DodgsonTidemanApproximation.php b/src/Algo/Methods/Dodgson/DodgsonTidemanApproximation.php index e432ac63..30131845 100644 --- a/src/Algo/Methods/Dodgson/DodgsonTidemanApproximation.php +++ b/src/Algo/Methods/Dodgson/DodgsonTidemanApproximation.php @@ -29,6 +29,7 @@ class DodgsonTidemanApproximation extends PairwiseStatsBased_Core implements Met //:: DODGSON ALGORITHM. ::// + #[\Override] protected function looking(array $challenge): int { return min($challenge); diff --git a/src/Algo/Methods/HighestAverages/Jefferson.php b/src/Algo/Methods/HighestAverages/Jefferson.php index 05a63b3f..5350470b 100644 --- a/src/Algo/Methods/HighestAverages/Jefferson.php +++ b/src/Algo/Methods/HighestAverages/Jefferson.php @@ -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)); diff --git a/src/Algo/Methods/HighestAverages/SainteLague.php b/src/Algo/Methods/HighestAverages/SainteLague.php index 7c112893..49ddb9af 100644 --- a/src/Algo/Methods/HighestAverages/SainteLague.php +++ b/src/Algo/Methods/HighestAverages/SainteLague.php @@ -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; diff --git a/src/Algo/Methods/LargestRemainder/LargestRemainder.php b/src/Algo/Methods/LargestRemainder/LargestRemainder.php index 34064f6e..a2ff7946 100644 --- a/src/Algo/Methods/LargestRemainder/LargestRemainder.php +++ b/src/Algo/Methods/LargestRemainder/LargestRemainder.php @@ -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(); @@ -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); diff --git a/src/Algo/Methods/Minimax/MinimaxMargin.php b/src/Algo/Methods/Minimax/MinimaxMargin.php index 44a34f22..6a666253 100644 --- a/src/Algo/Methods/Minimax/MinimaxMargin.php +++ b/src/Algo/Methods/Minimax/MinimaxMargin.php @@ -28,6 +28,7 @@ class MinimaxMargin extends PairwiseStatsBased_Core //:: SIMPSON ALGORITHM. ::// + #[\Override] protected function looking(array $challenge): int { return min($challenge); diff --git a/src/Algo/Methods/Minimax/MinimaxOpposition.php b/src/Algo/Methods/Minimax/MinimaxOpposition.php index ab6c7b18..28c4e377 100644 --- a/src/Algo/Methods/Minimax/MinimaxOpposition.php +++ b/src/Algo/Methods/Minimax/MinimaxOpposition.php @@ -28,6 +28,7 @@ class MinimaxOpposition extends PairwiseStatsBased_Core //:: SIMPSON ALGORITHM. ::// + #[\Override] protected function looking(array $challenge): int { return min($challenge); diff --git a/src/Algo/Methods/Minimax/MinimaxWinning.php b/src/Algo/Methods/Minimax/MinimaxWinning.php index 4c29ba36..48825401 100644 --- a/src/Algo/Methods/Minimax/MinimaxWinning.php +++ b/src/Algo/Methods/Minimax/MinimaxWinning.php @@ -28,6 +28,7 @@ class MinimaxWinning extends PairwiseStatsBased_Core //:: SIMPSON ALGORITHM. ::// + #[\Override] protected function looking(array $challenge): int { return min($challenge); diff --git a/src/Algo/Methods/STV/CPO_STV.php b/src/Algo/Methods/STV/CPO_STV.php index 409d64e7..27618969 100644 --- a/src/Algo/Methods/STV/CPO_STV.php +++ b/src/Algo/Methods/STV/CPO_STV.php @@ -67,6 +67,7 @@ class CPO_STV extends SingleTransferableVote /////////// COMPUTE /////////// + #[\Override] protected function compute(): void { Vote::initCache(); // Performances diff --git a/src/Algo/Methods/Schulze/SchulzeMargin.php b/src/Algo/Methods/Schulze/SchulzeMargin.php index 0ec10c1c..343da3ab 100644 --- a/src/Algo/Methods/Schulze/SchulzeMargin.php +++ b/src/Algo/Methods/Schulze/SchulzeMargin.php @@ -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]; diff --git a/src/Algo/Methods/Schulze/SchulzeRatio.php b/src/Algo/Methods/Schulze/SchulzeRatio.php index a2005e65..2bb3c320 100644 --- a/src/Algo/Methods/Schulze/SchulzeRatio.php +++ b/src/Algo/Methods/Schulze/SchulzeRatio.php @@ -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) { diff --git a/src/Algo/Methods/Schulze/SchulzeWinning.php b/src/Algo/Methods/Schulze/SchulzeWinning.php index b509f595..1f81b445 100644 --- a/src/Algo/Methods/Schulze/SchulzeWinning.php +++ b/src/Algo/Methods/Schulze/SchulzeWinning.php @@ -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]; diff --git a/src/Algo/Pairwise/FilteredPairwise.php b/src/Algo/Pairwise/FilteredPairwise.php index bb5c91f9..45d1056e 100644 --- a/src/Algo/Pairwise/FilteredPairwise.php +++ b/src/Algo/Pairwise/FilteredPairwise.php @@ -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]; diff --git a/src/DataManager/VotesManager.php b/src/DataManager/VotesManager.php index 022f9090..4158f730 100644 --- a/src/DataManager/VotesManager.php +++ b/src/DataManager/VotesManager.php @@ -22,6 +22,7 @@ class VotesManager extends ArrayManager { /////////// Data CallBack for external drivers /////////// + #[\Override] protected function decodeOneEntity(string $data): Vote { $vote = new Vote($data); @@ -33,6 +34,7 @@ protected function decodeOneEntity(string $data): Vote return $vote; } + #[\Override] protected function encodeOneEntity(Vote $data): string { if (($election = $this->getElection()) !== null) { @@ -42,6 +44,7 @@ protected function encodeOneEntity(Vote $data): string return str_replace([' > ', ' = '], ['>', '='], (string) $data); } + #[\Override] protected function preDeletedTask(Vote $object): void { $object->destroyLink($this->getElection()); @@ -49,12 +52,14 @@ protected function preDeletedTask(Vote $object): void /////////// 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) { @@ -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)) { diff --git a/src/Tools/Converters/CEF/CondorcetElectionFormat.php b/src/Tools/Converters/CEF/CondorcetElectionFormat.php index dbbfc629..1a85d362 100644 --- a/src/Tools/Converters/CEF/CondorcetElectionFormat.php +++ b/src/Tools/Converters/CEF/CondorcetElectionFormat.php @@ -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, diff --git a/src/Tools/Converters/DavidHillFormat.php b/src/Tools/Converters/DavidHillFormat.php index 3ffd4851..e0518b71 100644 --- a/src/Tools/Converters/DavidHillFormat.php +++ b/src/Tools/Converters/DavidHillFormat.php @@ -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 diff --git a/src/Tools/Converters/DebianFormat.php b/src/Tools/Converters/DebianFormat.php index 5a928414..1fd1d47e 100644 --- a/src/Tools/Converters/DebianFormat.php +++ b/src/Tools/Converters/DebianFormat.php @@ -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