Reedy has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/66120


Change subject: Type hints. Fixup missing return values
......................................................................

Type hints. Fixup missing return values

Fixes bug: 42462

Change-Id: I879feacba211ac3cfd1eb55629300b78ef2e4c0c
---
M cli/convertVotes.php
M cli/import.php
R cli/voterList.php
M includes/ballots/ApprovalBallot.php
M includes/ballots/Ballot.php
M includes/ballots/ChooseBallot.php
M includes/ballots/PreferentialBallot.php
M includes/ballots/RadioRangeBallot.php
M includes/crypt/Crypt.php
M includes/entities/Election.php
M includes/entities/Entity.php
M includes/entities/Option.php
M includes/entities/Question.php
M includes/main/Base.php
M includes/main/Context.php
M includes/talliers/SchulzeTallier.php
M includes/talliers/Tallier.php
M includes/user/Auth.php
18 files changed, 202 insertions(+), 38 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SecurePoll 
refs/changes/20/66120/1

diff --git a/cli/convertVotes.php b/cli/convertVotes.php
index 4adf726..3e77daf 100644
--- a/cli/convertVotes.php
+++ b/cli/convertVotes.php
@@ -33,7 +33,7 @@
 
 
 class SecurePoll_ConvertVotes {
-       var $context;
+       var $context, $election;
 
        function convertFile( $fileName ) {
                $this->context = SecurePoll_Context::newFromXmlFile( $fileName 
);
diff --git a/cli/import.php b/cli/import.php
index 9314389..50e233e 100644
--- a/cli/import.php
+++ b/cli/import.php
@@ -38,6 +38,7 @@
        exit( 1 );
 }
 
+$options = array();
 foreach ( array( 'update-msgs', 'replace' ) as $optName ) {
        if ( !isset( $options[$optName] ) ) {
                $options[$optName] = false;
@@ -47,6 +48,11 @@
 $success = spImportDump( $args[0], $options );
 exit( $success ? 0 : 1 );
 
+/**
+ * @param $fileName string
+ * @param $options
+ * @return bool
+ */
 function spImportDump( $fileName, $options ) {
        $store = new SecurePoll_XMLStore( $fileName );
        $success = $store->readFile();
@@ -96,13 +102,18 @@
                }
                if ( !$success ) {
                        $dbw->rollback();
+                       echo "Faied!\n";
                        return false;
                }
        }
        $dbw->commit();
+       echo "Finished!\n";
        return true;
 }
 
+/**
+ * @param $electionId int|string
+ */
 function spDeleteElection( $electionId ) {
        $dbw = wfGetDB( DB_MASTER );
 
@@ -136,6 +147,10 @@
        $dbw->delete( 'securepoll_entity', array( 'en_id' => $entityIds ), 
__METHOD__ );
 }
 
+/**
+ * @param $type string
+ * @param $id string
+ */
 function spInsertEntity( $type, $id ) {
        $dbw = wfGetDB( DB_MASTER );
        $dbw->insert( 'securepoll_entity', 
@@ -147,6 +162,11 @@
        );
 }
 
+/**
+ * @param $store SecurePoll_Store
+ * @param $electionInfo
+ * @return bool
+ */
 function spImportConfiguration( $store, $electionInfo ) {
        $dbw = wfGetDB( DB_MASTER );
        $sourceIds = array();
@@ -166,7 +186,6 @@
                ),
                __METHOD__ );
        $sourceIds[] = $electionInfo['id'];
-
 
        # Questions
        $index = 1;
@@ -216,6 +235,10 @@
        return true;
 }
 
+/**
+ * @param $store SecurePoll_Store
+ * @param $entityIds
+ */
 function spInsertMessages( $store, $entityIds ) {
        $langs = $store->getLangList( $entityIds );
        $insertBatch = array();
@@ -238,6 +261,11 @@
        }
 }
 
+/**
+ * @param $store SecurePoll_Store
+ * @param $electionInfo
+ * @return bool
+ */
 function spUpdateMessages( $store, $electionInfo ) {
        $entityIds = array( $electionInfo['id'] );
        foreach ( $electionInfo['questions'] as $questionInfo ) {
@@ -253,5 +281,6 @@
 
        # Insert new messages
        spInsertMessages( $store, $entityIds );
+       return true;
 }
 
diff --git a/voterList.php b/cli/voterList.php
similarity index 100%
rename from voterList.php
rename to cli/voterList.php
diff --git a/includes/ballots/ApprovalBallot.php 
b/includes/ballots/ApprovalBallot.php
index 5fe2009..45225b4 100644
--- a/includes/ballots/ApprovalBallot.php
+++ b/includes/ballots/ApprovalBallot.php
@@ -7,7 +7,12 @@
        function getTallyTypes() {
                return array( 'plurality' );
        }
-       
+
+       /**
+        * @param $question SecurePoll_Question
+        * @param $options array
+        * @return string
+        */
        function getQuestionForm( $question, $options ) {
                global $wgRequest;
                $name = 'securepoll_q' . $question->getId();
@@ -28,6 +33,11 @@
                return $s;
        }
 
+       /**
+        * @param $question SecurePoll_Question
+        * @param $status Status
+        * @return string
+        */
        function submitQuestion( $question, $status ) {
                global $wgRequest;
 
diff --git a/includes/ballots/Ballot.php b/includes/ballots/Ballot.php
index f349a40..15cdf78 100644
--- a/includes/ballots/Ballot.php
+++ b/includes/ballots/Ballot.php
@@ -17,11 +17,10 @@
         * Get the HTML form segment for a single question
         * @param $question SecurePoll_Question
         * @param $options Array of options, in the order they should be 
displayed
-        * @param $prevStatus Status of previous form submission
         * @return string
         */
        abstract function getQuestionForm( $question, $options );
-       
+
        /**
         * Get any extra messages that this ballot type uses to render 
questions.
         * Used to get the list of translatable messages for TranslatePage.
@@ -55,10 +54,11 @@
        /**
         * Construct a string record for a given question, during form 
submission.
         *
-        * If there is a problem with the form data, the function should set a 
+        * If there is a problem with the form data, the function should set a
         * fatal error in the $status object and return null.
         *
-        * @param Status
+        * @param $question
+        * @param $status
         * @return string
         */
        abstract function submitQuestion( $question, $status );
@@ -86,6 +86,8 @@
         * @param $context SecurePoll_Context
         * @param $type string
         * @param $election SecurePoll_Election
+        * @throws MWException
+        * @return SecurePoll_Ballot
         */
        static function factory( $context, $type, $election ) {
                switch ( $type ) {
@@ -177,7 +179,7 @@
        function formatStatus( $status ) {
                return $status->sp_getHTML( $this->usedErrorIds );
        }
-       
+
        /**
         * Get the way the voter cast their vote previously, if we're allowed
         * to show that information.
@@ -185,11 +187,11 @@
         *     of unpackRecord().
         */
        function getCurrentVote(){
-               
+
                if( !$this->election->getOption( 'show-change' ) ){
                        return false;
                }
-                       
+
                $auth = $this->election->getAuth();
 
                # Get voter from session
diff --git a/includes/ballots/ChooseBallot.php 
b/includes/ballots/ChooseBallot.php
index 8d60b3f..4e72090 100644
--- a/includes/ballots/ChooseBallot.php
+++ b/includes/ballots/ChooseBallot.php
@@ -37,6 +37,11 @@
                return $s;
        }
 
+       /**
+        * @param $question SecurePoll_Question
+        * @param $status Status
+        * @return string
+        */
        function submitQuestion( $question, $status ) {
                global $wgRequest;
                $result = $wgRequest->getInt( 'securepoll_q' . 
$question->getId() );
diff --git a/includes/ballots/PreferentialBallot.php 
b/includes/ballots/PreferentialBallot.php
index 5494f57..0cc288a 100644
--- a/includes/ballots/PreferentialBallot.php
+++ b/includes/ballots/PreferentialBallot.php
@@ -12,6 +12,11 @@
                return array( 'schulze' );
        }
 
+       /**
+        * @param $question SecurePoll_Question
+        * @param Array $options
+        * @return string
+        */
        function getQuestionForm( $question, $options ) {
                global $wgRequest;
                $name = 'securepoll_q' . $question->getId();
@@ -36,6 +41,11 @@
                return $s;
        }
 
+       /**
+        * @param $question SecurePoll_Question
+        * @param $status Status
+        * @return string
+        */
        function submitQuestion( $question, $status ) {
                global $wgRequest;
 
diff --git a/includes/ballots/RadioRangeBallot.php 
b/includes/ballots/RadioRangeBallot.php
index 5b91de1..2c55dcc 100644
--- a/includes/ballots/RadioRangeBallot.php
+++ b/includes/ballots/RadioRangeBallot.php
@@ -23,6 +23,11 @@
                return array( 'plurality', 'histogram-range' );
        }
 
+       /**
+        * @param $question SecurePoll_Question
+        * @return array
+        * @throws MWException
+        */
        function getMinMax( $question ) {
                $min = intval( $question->getProperty( 'min-score' ) );
                $max = intval( $question->getProperty( 'max-score' ) );
@@ -32,6 +37,11 @@
                return array( $min, $max );
        }
 
+       /**
+        * @param $question SecurePoll_Question
+        * @return int
+        * @throws MWException
+        */
        function getColumnDirection( $question ) {
                $order = $question->getProperty( 'column-order' );
                if ( !$order ) {
@@ -45,7 +55,10 @@
                }
        }
 
-
+       /**
+        * @param $question SecurePoll_Question
+        * @return array
+        */
        function getScoresLeftToRight( $question ) {
                $incr = $this->getColumnDirection( $question );
                list( $min, $max ) = $this->getMinMax( $question );
@@ -59,8 +72,12 @@
                return range( $left, $right );
        }
 
+       /**
+        * @param $question SecurePoll_Question
+        * @return array
+        */
        function getColumnLabels( $question ) {
-               list( $min, $max ) = $this->getMinMax( $question );
+               //list( $min, $max ) = $this->getMinMax( $question );
                $labels = array();
                $useMessageLabels = $question->getProperty( 'column-label-msgs' 
);
                $scores = $this->getScoresLeftToRight( $question );
@@ -103,6 +120,11 @@
                }
        }
 
+       /**
+        * @param $question SecurePoll_Question
+        * @param $options array
+        * @return array
+        */
        function getQuestionForm( $question, $options ) {
                global $wgRequest;
                $name = 'securepoll_q' . $question->getId();
@@ -142,6 +164,11 @@
                return $s;
        }
 
+       /**
+        * @param $question SecurePoll_Question
+        * @param $status Status
+        * @return array
+        */
        function submitQuestion( $question, $status ) {
                global $wgRequest, $wgLang;
 
diff --git a/includes/crypt/Crypt.php b/includes/crypt/Crypt.php
index 65c7719..e59e634 100644
--- a/includes/crypt/Crypt.php
+++ b/includes/crypt/Crypt.php
@@ -55,6 +55,7 @@
 
        /**
         * Constructor.
+        * @param $context
         * @param $election SecurePoll_Election
         */
        function __construct( $context, $election ) {
@@ -110,6 +111,7 @@
        /**
         * Import a given exported key.
         * @param $key string The full key data.
+        * @return Status
         */
        function importKey( $key ) {
                # Import the key
@@ -212,7 +214,7 @@
        /**
         * Decrypt some data. When successful, the value member of the Status 
object 
         * will contain the encrypted record.
-        * @param string $record
+        * @param $encrypted string
         * @return Status
         */
        function decrypt( $encrypted ) {
@@ -249,6 +251,9 @@
                return $status;
        }
 
+       /**
+        * @return bool
+        */
        function canDecrypt() {
                $decryptKey = strval( $this->election->getProperty( 
'gpg-decrypt-key' ) );
                return $decryptKey !== '';
diff --git a/includes/entities/Election.php b/includes/entities/Election.php
index b9aae6f..ae1ee20 100644
--- a/includes/entities/Election.php
+++ b/includes/entities/Election.php
@@ -63,12 +63,12 @@
        var $startDate, $endDate, $authType;
 
        /**
-        * Constructor. 
+        * Constructor.
         *
-        * Do not use this constructor directly, instead use 
-        * SecurePoll_Context::getElection(). 
-        *
-        * @param $id integer
+        * Do not use this constructor directly, instead use
+        * SecurePoll_Context::getElection().
+        * @param $context SecurePoll_Context
+        * @param string $info
         */
        function __construct( $context, $info ) {
                parent::__construct( $context, 'election', $info );
@@ -121,7 +121,8 @@
 
        /**
         * Returns true if the election has started.
-        * @param $ts The reference timestamp, or false for now.
+        * @param $ts string|bool The reference timestamp, or false for now.
+        * @return bool
         */
        function isStarted( $ts = false ) {
                if ( $ts === false ) {
@@ -132,7 +133,7 @@
 
        /**
         * Returns true if the election has finished.
-        * @param $ts The reference timestamp, or false for now.
+        * @param $ts string|bool The reference timestamp, or false for now.
         */
        function isFinished( $ts = false ) {
                if ( $ts === false ) {
@@ -155,7 +156,7 @@
        /**
         * Determine whether a voter would be qualified to vote in this 
election, 
         * based on the given associative array of parameters.
-        * @param $params Associative array
+        * @param $params array Associative array
         * @return Status
         */
        function getQualifiedStatus( $params ) {
@@ -233,6 +234,7 @@
        /**
         * Returns true if the user is an admin of the current election.
         * @param $user User
+        * @return bool
         */
        function isAdmin( $user ) {
                $admins = array_map( 'trim', explode( '|', $this->getProperty( 
'admins' ) ) );
@@ -303,7 +305,8 @@
        /**
         * Get the cryptography module for this election, or false if none is
         * defined.
-        * @return SecurePoll_Crypt or false
+        * @throws MWException
+        * @return SecurePoll_Crypt|bool
         */
        function getCrypt() {
                $type = $this->getProperty( 'encrypt-type' );
@@ -415,6 +418,7 @@
         * Tally the valid votes for this election.
         * Returns a Status object. On success, the value property will contain 
a
         * SecurePoll_ElectionTallier object.
+        * @return Status
         */
        function tally() {
                $tallier = $this->context->newElectionTallier( $this );
diff --git a/includes/entities/Entity.php b/includes/entities/Entity.php
index 04444a4..6cdaf83 100644
--- a/includes/entities/Entity.php
+++ b/includes/entities/Entity.php
@@ -22,7 +22,7 @@
         * child constructor.
         * @param $context SecurePoll_Context
         * @param $type string
-        * @param $info Associative array of entity info
+        * @param $info array Associative array of entity info
         */
        function __construct( $context, $type, $info ) {
                $this->context = $context;
@@ -132,6 +132,7 @@
         *
         * @param $name string
         * @param $language string
+        * @return bool
         */
        function getRawMessage( $name, $language ) {
                if ( empty( $this->messagesLoaded[$language] ) ) {
@@ -146,6 +147,7 @@
         * a placeholder string is returned.
         *
         * @param $name string
+        * @return bool|string
         */
        function getMessage( $name ) {
                foreach ( $this->context->languages as $language ) {
@@ -200,6 +202,7 @@
         * is passed back.
         * @param $name string
         * @param $default mixed
+        * @return bool|mixed
         */
        function getProperty( $name, $default = false ) {
                if ( $this->properties === null ) {
diff --git a/includes/entities/Option.php b/includes/entities/Option.php
index 43c13f7..066011a 100644
--- a/includes/entities/Option.php
+++ b/includes/entities/Option.php
@@ -8,7 +8,7 @@
        /**
         * Constructor
         * @param $context SecurePoll_Context
-        * @param $info Associative array of entity info
+        * @param $info array Associative array of entity info
         */
        function __construct( $context, $info ) {
                parent::__construct( $context, 'option', $info );
diff --git a/includes/entities/Question.php b/includes/entities/Question.php
index 02bb90d..8bee4c3 100644
--- a/includes/entities/Question.php
+++ b/includes/entities/Question.php
@@ -10,7 +10,7 @@
        /**
         * Constructor
         * @param $context SecurePoll_Context
-        * @param $info Associative array of entity info
+        * @param $info array Associative array of entity info
         */
        function __construct( $context, $info ) {
                parent::__construct( $context, 'question', $info );
diff --git a/includes/main/Base.php b/includes/main/Base.php
index 288c4d8..56c99a6 100644
--- a/includes/main/Base.php
+++ b/includes/main/Base.php
@@ -18,7 +18,7 @@
                'vote' => 'SecurePoll_VotePage',
        );
 
-       var $sp_context;
+       var $sp_context, $request;
 
        /**
         * Constructor
diff --git a/includes/main/Context.php b/includes/main/Context.php
index f6d9556..c31e85c 100644
--- a/includes/main/Context.php
+++ b/includes/main/Context.php
@@ -164,6 +164,7 @@
 
        /**
         * Create a voter object from the database
+        * @param $id
         * @return SecurePoll_Voter or false if the ID is not valid
         */
        function getVoter( $id ) {
@@ -197,8 +198,9 @@
         * This is an internal interface for SecurePoll_Entity, generally you 
         * should use SecurePoll_Entity::getMessage() instead.
         *
-        * @param $lang Language code
-        * @param $ids Entity IDs
+        * @param $lang string Language code
+        * @param $ids array Entity IDs
+        * @return array
         */
        function getMessages( $lang, $ids ) {
                if ( isset( $this->messagesLoaded[$lang] ) ) {
@@ -227,9 +229,10 @@
         * This is an internal interface for SecurePoll_Entity, generally you 
         * should use SecurePoll_Entity::getMessage() instead.
         *
-        * @param $lang Language code
-        * @param $id Entity ID
-        * @param $key Message key
+        * @param $lang string Language code
+        * @param $id string|int Entity ID
+        * @param $key string Message key
+        * @return bool
         */
        function getMessage( $lang, $id, $key ) {
                if ( !isset( $this->messagesLoaded[$lang][$id] ) ) {
@@ -254,38 +257,78 @@
                return $this->db;
        }
 
+       /**
+        * @param $info
+        * @return SecurePoll_Election
+        */
        function newElection( $info ) {
                return new SecurePoll_Election( $this, $info );
        }
 
+       /**
+        * @param $info
+        * @return SecurePoll_Question
+        */
        function newQuestion( $info ) {
                return new SecurePoll_Question( $this, $info );
        }
 
+       /**
+        * @param $info
+        * @return SecurePoll_Option
+        */
        function newOption( $info ) {
                return new SecurePoll_Option( $this, $info );
        }
 
+       /**
+        * @param $type
+        * @param $election
+        * @return bool|SecurePoll_GpgCrypt
+        */
        function newCrypt( $type, $election ) {
                return SecurePoll_Crypt::factory( $this, $type, $election );
        }
 
+       /**
+        * @param $type
+        * @param $electionTallier
+        * @param $question
+        * @return SecurePoll_Tallier
+        */
        function newTallier( $type, $electionTallier, $question ) {
                return SecurePoll_Tallier::factory( $this, $type, 
$electionTallier, $question );
        }
 
+       /**
+        * @param $type
+        * @param $election
+        * @return SecurePoll_Ballot
+        */
        function newBallot( $type, $election ) {
                return SecurePoll_Ballot::factory( $this, $type, $election );
        }
 
+       /**
+        * @param $type
+        * @return SecurePoll_Auth
+        */
        function newAuth( $type ) {
                return SecurePoll_Auth::factory( $this, $type );
        }
 
+       /**
+        * @param $params
+        * @return SecurePoll_Voter
+        */
        function newVoter( $params ) {
                return new SecurePoll_Voter( $this, $params );
-       }       
+       }
 
+       /**
+        * @param $election
+        * @return SecurePoll_ElectionTallier
+        */
        function newElectionTallier( $election ) {
                return new SecurePoll_ElectionTallier( $this, $election );
        }
@@ -295,8 +338,9 @@
         * but omitting the $obj->context member variables for brevity.
         *
         * @param $var mixed
-        * @param $return True to return the text instead of echoing
-        * @param $level Recursion level, leave this as zero when calling.
+        * @param $return bool True to return the text instead of echoing
+        * @param $level int Recursion level, leave this as zero when calling.
+        * @return mixed|string
         */
        function varDump( $var, $return = false, $level = 0 ) {
                $tab = '    ';
@@ -304,7 +348,7 @@
                if ( is_array( $var ) ) {
                        $s = "array(\n";
                        foreach ( $var as $key => $value ) {
-                               $s .= "$indent$tab" . $this->varDump( $key, 
true, $level + 1 ) . " => " . 
+                               $s .= "$indent$tab" . $this->varDump( $key, 
true, $level + 1 ) . " => " .
                                        $this->varDump( $value, true, $level + 
1 ) . ",\n";
                        }
                        $s .= "{$indent})";
@@ -333,8 +377,12 @@
                }
        }
 
+       /**
+        * @param $resource
+        * @return string
+        */
        function getResourceUrl( $resource ) {
                global $wgScriptPath;
                return 
"$wgScriptPath/extensions/SecurePoll/resources/$resource";
-       }       
+       }
 }
diff --git a/includes/talliers/SchulzeTallier.php 
b/includes/talliers/SchulzeTallier.php
index fd409b3..6e82fde 100644
--- a/includes/talliers/SchulzeTallier.php
+++ b/includes/talliers/SchulzeTallier.php
@@ -7,6 +7,11 @@
  * debian-vote (but not devotee).
  */
 class SecurePoll_SchulzeTallier extends SecurePoll_PairwiseTallier {
+
+       /**
+        * @param $victories
+        * @return array
+        */
        function getPathStrengths( $victories ) {
                # This algorithm follows Markus Schulze, "A New Monotonic, 
Clone-Independent, Reversal
                # Symmetric, and Condorcet-Consistent Single-Winner Election 
Method" and also 
diff --git a/includes/talliers/Tallier.php b/includes/talliers/Tallier.php
index ade7364..1eb9b9c 100644
--- a/includes/talliers/Tallier.php
+++ b/includes/talliers/Tallier.php
@@ -14,6 +14,14 @@
 
        abstract function finishTally();
 
+       /**
+        * @param $context
+        * @param $type
+        * @param $electionTallier
+        * @param $question
+        * @return SecurePoll_Tallier
+        * @throws MWException
+        */
        static function factory( $context, $type, $electionTallier, $question ) 
{
                switch ( $type ) {
                case 'plurality':
@@ -44,6 +52,10 @@
                }
        }
 
+       /**
+        * @param $ranks
+        * @return string
+        */
        function convertRanksToHtml( $ranks ) {
                $s = "<table class=\"securepoll-table\">";
                $ids = array_keys( $ranks );
@@ -65,6 +77,10 @@
                return $s;
        }
 
+       /**
+        * @param $ranks
+        * @return string
+        */
        function convertRanksToText( $ranks ) {
                $s = '';
                $ids = array_keys( $ranks );
diff --git a/includes/user/Auth.php b/includes/user/Auth.php
index f9fe709..de21225 100644
--- a/includes/user/Auth.php
+++ b/includes/user/Auth.php
@@ -258,7 +258,7 @@
                $attached = $centralUser->queryAttached();
                $blockCount = 0;
                
-               foreach( $attached as $wiki => $data ) {
+               foreach( $attached as $data ) {
                        if ( $data['blocked'] ) {
                                $blockCount++;
                        }
@@ -278,7 +278,7 @@
         * @return Status
         */
        function requestLogin( $election ) {
-               global $wgRequest;
+               global $wgRequest, $wgSecurePollScript;
 
                $urlParamNames = array( 'id', 'token', 'wiki', 'site', 'lang', 
'domain' );
                $vars = array();

-- 
To view, visit https://gerrit.wikimedia.org/r/66120
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I879feacba211ac3cfd1eb55629300b78ef2e4c0c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SecurePoll
Gerrit-Branch: master
Gerrit-Owner: Reedy <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to