Get Winner / Loser

Original Condorcet method Winner / Loser

Election->getCondorcetWinner() Election->getCondorcetLoser()

$winner = $election->getCondorcetWinner();
$loser = $election->getCondorcetLoser();

if ($winner !== null) {
    echo 'My winner is ' . $winner->getName();
} else {
    echo 'There is no winner. Cause of Condorcet paradox.';
}

if ($loser !== null) {
    echo 'My loser is ' . (string) $loser ; // Little tips : \CondorcetPHP\Condorcet\Candidate implement __toString() magic method.
} else {
    echo 'There is no loser. Cause of Condorcet paradox.';
}

Get the winner from an advanced method

If there is not a regular Condorcet Winner or Loser, the process to a special winner(s) using an advanced method.

Election->getCondorcetWinner() Election->getCondorcetLoser()

$election->getWinner(); // With the default object method (Default: Schulze Winning)
$election->getWinner('Copeland'); // Name of a valid method

$election->getLoser(); // With the default object method (Default: Schulze Winning)
$election->getLoser('Kemeny-Young'); // Name of a valid method

Condorcet::getDefaultMethod(); // CondorcetPHP\Condorcet\Algo\Methods\Schulze\SchulzeWinning

In the case of using some advanced Condorcet methods, like Schulze. getWinner() or getLoser() methods can return one or multiple winners/losers. If there is only one, a Candidate object will be returned, or else an array of Candidate objects.

From a Result object

Result->getCondorcetWinner() Result->getCondorcetLoser()

Result->getWinner() Result->getLoser()

Will return an immutable result object. Winner/Loser will depend of the method.

$result = $election->getResult('Schulze');

// All those below return null or the candidate object
$result->getWinner();
$result->getLoser();

// All those below return null, the candidate object or an array of candidates objects
$result->getCondorcetWinner();
$result->getCondorcetLoser();