src/STV/ElectionRunner.php
protected function checkCandidates(array $candidates): bool
    {
        $elected = false;
        $candidatesToElect = [];

        $this->logger->info('Checking if candidates have passed quota');

        if (empty($candidates)) {
            throw new LogicException('There are no more candidates left');
        }

        foreach ($candidates as $i => $candidate) {
            if ($candidate->getState() !== Candidate::RUNNING) {
                throw new LogicException('Candidate is not marked as not running but has not been excluded');
            }

            $votes = $candidate->getVotes();

            $this->logger->debug("Checking candidate ($candidate) with $votes", ['candidate' => $candidate]);

            // p. 48(1)
            // Immediately elect a candidate if they hit the quota
            // We check all the candidates, see who has hit the quota,
            // add them to a queue, then elect those who have hit the quota to prevent
            // surplus allocations pushing a candidate over the quota early.
            if ($votes >= $this->quota) {
                $candidatesToElect[] = $candidate;
                $elected = true;
            }
        }

        // TODO: Put this in a try, and catch the RuntimeError.
        // Then sort by the surplus, and fill available seats.
        // If have same surplus then select randomly (Contary to Scottish STV)
        // p. 50
        $this->electCandidates($candidatesToElect);

        $this->logger->info(('Candidate checking complete. Elected: '.count($candidatesToElect)));

        return $elected;
    }
protected function checkCandidates(array $candidates): bool
    {
        $elected = false;
        $candidatesToElect = [];

        $this->logger->info('Checking if candidates have passed quota');

        if (empty($candidates)) {
            throw new LogicException('There are no more candidates left');
        }

        foreach ($candidates as $i => $candidate) {
            if ($candidate->getState() !== Candidate::RUNNING) {
                throw new LogicException('Candidate is not marked as not running but has not been excluded');
            }

            $votes = $candidate->getVotes();

            $this->logger->debug("Checking candidate ($candidate) with $votes", ['candidate' => $candidate]);

            // p. 48(1)
            // Immediately elect a candidate if they hit the quota
            // We check all the candidates, see who has hit the quota,
            // add them to a queue, then elect those who have hit the quota to prevent
            // surplus allocations pushing a candidate over the quota early.
            if ($votes >= $this->quota) {
                $candidatesToElect[] = $candidate;
                $elected = true;
            }
        }

        // TODO: Put this in a try, and catch the RuntimeError.
        // Then sort by the surplus, and fill available seats.
        // If have same surplus then select randomly (Contary to Scottish STV)
        // p. 50
        $this->electCandidates($candidatesToElect);

        $this->logger->info(('Candidate checking complete. Elected: '.count($candidatesToElect)));

        return $elected;
    }
protected function checkCandidates ( array $ candidates ) : bool { $ elected = false ; $ candidatesToElect = [ ] ; $ this -> logger -> info ( 'Checking if candidates have passed quota' ) ; if ( empty ( $ candidates ) ) { throw new LogicException ( 'There are no more candidates left' ) ; } foreach ( $ candidates as $ i => $ candidate ) { if ( $ candidate -> getState ( ) !== Candidate :: RUNNING ) { throw new LogicException ( 'Candidate is not marked as not running but has not been excluded' ) ; } $ votes = $ candidate -> getVotes ( ) ; $ this -> logger -> debug ( "Checking candidate ($candidate) with $votes" , [ 'candidate' => $ candidate ] ) ; // p. 48(1) // Immediately elect a candidate if they hit the quota // We check all the candidates, see who has hit the quota, // add them to a queue, then elect those who have hit the quota to prevent // surplus allocations pushing a candidate over the quota early. if ( $ votes >= $ this -> quota ) { $ candidatesToElect [ ] = $ candidate ; $ elected = true ; } } // TODO: Put this in a try, and catch the RuntimeError. // Then sort by the surplus, and fill available seats. // If have same surplus then select randomly (Contary to Scottish STV) // p. 50 $ this -> electCandidates ( $ candidatesToElect ) ; $ this -> logger -> info ( ( 'Candidate checking complete. Elected: ' . count ( $ candidatesToElect ) ) ) ; return $ elected ; }
Check if any candidates have reached the quota and can be elected.

@param Candidate[] $candidates Array of active candidates to check

@return bool Whether any candidates were changed to elected
Check if any candidates have reached the quota and can be elected .