public function addCandidate ($candidate_id = null) : Candidate
    {
        // only if the vote has not started
        if ( $this->_State > 1 ) :
            throw new CondorcetException(2);
        endif;

        // Filter
        if ( is_bool($candidate_id) || is_array($candidate_id) || (is_object($candidate_id) && !($candidate_id instanceof Candidate)) ) :
            throw new CondorcetException(1, $candidate_id);
        endif;


        // Process
        if ( empty($candidate_id) ) :
            while ( !$this->canAddCandidate($this->_i_CandidateId) ) :
                $this->_i_CandidateId++;
            endwhile;

            $newCandidate = new Candidate($this->_i_CandidateId);
        else : // Try to add the candidate_id
            $newCandidate = ($candidate_id instanceof Candidate) ? $candidate_id : new Candidate ((string) $candidate_id);

            if ( !$this->canAddCandidate($newCandidate) ) :
                throw new CondorcetException(3,$candidate_id);
            endif;
        endif;

        // Register it
        $this->_Candidates[] = $newCandidate;

        // Linking
        $newCandidate->registerLink($this);

        // Disallow other candidate object name matching 
        $newCandidate->setProvisionalState(false);

        return $newCandidate;
    }
public function addCandidate ($candidate_id = null) : Candidate
    {
        // only if the vote has not started
        if ( $this->_State > 1 ) :
            throw new CondorcetException(2);
        endif;

        // Filter
        if ( is_bool($candidate_id) || is_array($candidate_id) || (is_object($candidate_id) && !($candidate_id instanceof Candidate)) ) :
            throw new CondorcetException(1, $candidate_id);
        endif;


        // Process
        if ( empty($candidate_id) ) :
            while ( !$this->canAddCandidate($this->_i_CandidateId) ) :
                $this->_i_CandidateId++;
            endwhile;

            $newCandidate = new Candidate($this->_i_CandidateId);
        else : // Try to add the candidate_id
            $newCandidate = ($candidate_id instanceof Candidate) ? $candidate_id : new Candidate ((string) $candidate_id);

            if ( !$this->canAddCandidate($newCandidate) ) :
                throw new CondorcetException(3,$candidate_id);
            endif;
        endif;

        // Register it
        $this->_Candidates[] = $newCandidate;

        // Linking
        $newCandidate->registerLink($this);

        // Disallow other candidate object name matching 
        $newCandidate->setProvisionalState(false);

        return $newCandidate;
    }
public function addCandidate ( $ candidate_id = null ) : Candidate { // only if the vote has not started if ( $ this -> _State > 1 ) : throw new CondorcetException ( 2 ) ; endif ; // Filter if ( is_bool ( $ candidate_id ) || is_array ( $ candidate_id ) || ( is_object ( $ candidate_id ) && ! ( $ candidate_id instanceof Candidate ) ) ) : throw new CondorcetException ( 1 , $ candidate_id ) ; endif ; // Process if ( empty ( $ candidate_id ) ) : while ( ! $ this -> canAddCandidate ( $ this -> _i_CandidateId ) ) : $ this -> _i_CandidateId ++ ; endwhile ; $ newCandidate = new Candidate ( $ this -> _i_CandidateId ) ; else : // Try to add the candidate_id $ newCandidate = ( $ candidate_id instanceof Candidate ) ? $ candidate_id : new Candidate ( ( string ) $ candidate_id ) ; if ( ! $ this -> canAddCandidate ( $ newCandidate ) ) : throw new CondorcetException ( 3 , $ candidate_id ) ; endif ; endif ; // Register it $ this -> _Candidates [ ] = $ newCandidate ; // Linking $ newCandidate -> registerLink ( $ this ) ; // Disallow other candidate object name matching  $ newCandidate -> setProvisionalState ( false ) ; return $ newCandidate ; }
Add a vote candidate before voting
Add a vote candidate before voting