Thiemo Kreuz (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/400402 )

Change subject: Add strict type hints to productin code
......................................................................

Add strict type hints to productin code

This is currently more a proof of concept patch. The biggest issue is
that I did not checked all hook handlers, to make sure they are really
providing objects of these types.

Change-Id: I885bd7db8d635c3c76080bc8faaa805af3f8eaf2
---
M includes/Api.php
M includes/Cache.php
M includes/Hooks/ApiHooksHandler.php
M includes/Hooks/ChangesListHooksHandler.php
M includes/Parser/ScoreParser.php
M includes/ThresholdLookup.php
M includes/WatchedItemQueryServiceExtension.php
7 files changed, 24 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ORES 
refs/changes/02/400402/1

diff --git a/includes/Api.php b/includes/Api.php
index 7543d1d..552816e 100644
--- a/includes/Api.php
+++ b/includes/Api.php
@@ -78,11 +78,11 @@
        /**
         * Make an ORES API request and return the decoded result.
         *
-        * @param array $params optional GET parameters
+        * @param array $params
         * @return array Decoded response
         *
         */
-       public function request( $params = [] ) {
+       public function request( array $params ) {
                $logger = LoggerFactory::getInstance( 'ORES' );
 
                $url = $this->getUrl();
diff --git a/includes/Cache.php b/includes/Cache.php
index 68f9bdf..5a96804 100644
--- a/includes/Cache.php
+++ b/includes/Cache.php
@@ -36,7 +36,7 @@
         *
         * @param callable $errorCallback the callback function
         */
-       public function setErrorCallback( $errorCallback ) {
+       public function setErrorCallback( callable $errorCallback ) {
                $this->errorCallback = $errorCallback;
        }
 
@@ -141,7 +141,7 @@
         * @return int The number of deleted rows
         * @see Database::select
         */
-       protected function deleteRows( $tables, $conditions, $join_conds, 
$batchSize = 1000 ) {
+       protected function deleteRows( array $tables, array $conditions, array 
$join_conds, $batchSize = 1000 ) {
                $dbr = \wfGetDB( DB_REPLICA );
                $dbw = \wfGetDB( DB_MASTER );
 
@@ -178,7 +178,7 @@
         *
         * @throws RuntimeException
         */
-       public function processRevision( &$dbData, $revision, array 
$revisionData ) {
+       public function processRevision( array &$dbData, $revision, array 
$revisionData ) {
                global $wgOresModelClasses;
                // Map to database fields.
 
diff --git a/includes/Hooks/ApiHooksHandler.php 
b/includes/Hooks/ApiHooksHandler.php
index b2e996d..16b177c 100644
--- a/includes/Hooks/ApiHooksHandler.php
+++ b/includes/Hooks/ApiHooksHandler.php
@@ -40,9 +40,9 @@
 use ORES\WatchedItemQueryServiceExtension;
 use RequestContext;
 use Title;
-use ResultWrapper;
 use WatchedItem;
 use WatchedItemQueryService;
+use Wikimedia\Rdbms\ResultWrapper;
 
 class ApiHooksHandler {
 
@@ -61,7 +61,7 @@
         * @param array &$params Parameter data
         * @param int $flags zero or OR-ed flags like 
ApiBase::GET_VALUES_FOR_HELP
         */
-       public static function onAPIGetAllowedParams( &$module, &$params, 
$flags ) {
+       public static function onAPIGetAllowedParams( ApiBase &$module, array 
&$params, $flags ) {
                if ( $module instanceof ApiQueryRevisions ||
                        $module instanceof ApiQueryAllRevisions ||
                        $module instanceof ApiQueryRecentChanges ||
@@ -197,7 +197,7 @@
         * @param ResultWrapper|bool $res
         * @param array &$hookData Inter-hook communication
         */
-       public static function onApiQueryBaseAfterQuery( ApiQueryBase $module, 
$res, &$hookData ) {
+       public static function onApiQueryBaseAfterQuery( ApiQueryBase $module, 
$res, array &$hookData ) {
                if ( !$res ) {
                        return;
                }
@@ -255,7 +255,7 @@
         * @param int[] $revids Revision IDs
         * @return array [ array $scores, bool $needsContinuation ]
         */
-       public static function loadScoresForRevisions( $revids ) {
+       public static function loadScoresForRevisions( array $revids ) {
                global $wgOresAPIMaxBatchJobs, $wgOresRevisionsPerBatch;
 
                $needsContinuation = false;
@@ -350,7 +350,7 @@
         * @param string[] $models
         * @return array
         */
-       private static function processRevision( $revid, $data, $models ) {
+       private static function processRevision( $revid, array $data, array 
$models ) {
                global $wgOresModelClasses;
                $parser = new ScoreParser(
                        MediaWikiServices::getInstance()->getService( 
'ORESModelLookup' ),
@@ -390,7 +390,7 @@
         * @param array &$hookData Inter-hook communication
         * @return bool False to stop processing the result set
         */
-       public static function onApiQueryBaseProcessRow( $module, $row, &$data, 
&$hookData ) {
+       public static function onApiQueryBaseProcessRow( ApiQueryBase $module, 
$row, array &$data, array &$hookData ) {
                if ( isset( $hookData['oresField'] ) &&
                        ( !$hookData['oresCheckRCType'] ||
                                (int)$row->rc_type === RC_NEW || 
(int)$row->rc_type === RC_EDIT
@@ -471,7 +471,7 @@
         * @param array &$options
         */
        public static function 
onApiQueryWatchlistPrepareWatchedItemQueryServiceOptions(
-               ApiQueryBase $module, $params, &$options
+               ApiQueryBase $module, array $params, array &$options
        ) {
                if ( in_array( 'oresscores', $params['prop'], true ) ) {
                        $options['includeFields'][] = 'oresscores';
@@ -500,7 +500,7 @@
         * @param array &$output
         */
        public static function onApiQueryWatchlistExtractOutputData(
-               ApiQueryBase $module, WatchedItem $watchedItem, 
$recentChangeInfo, &$output
+               ApiQueryBase $module, WatchedItem $watchedItem, array 
$recentChangeInfo, array &$output
        ) {
                if ( isset( $recentChangeInfo['oresScores'] ) ) {
                        self::addScoresForAPI( $output, 
$recentChangeInfo['oresScores'] );
diff --git a/includes/Hooks/ChangesListHooksHandler.php 
b/includes/Hooks/ChangesListHooksHandler.php
index 93c7d79..b6a722e 100644
--- a/includes/Hooks/ChangesListHooksHandler.php
+++ b/includes/Hooks/ChangesListHooksHandler.php
@@ -464,8 +464,8 @@
        public static function onOldChangesListRecentChangesLine(
                ChangesList &$changesList,
                &$s,
-               $rc,
-               &$classes = []
+               RecentChange $rc,
+               array &$classes = []
        ) {
                if ( !Hooks::oresUiEnabled( $changesList->getUser() ) ) {
                        return;
@@ -500,7 +500,7 @@
         * @param IContextSource $context
         * @return bool
         */
-       public static function getScoreRecentChangesList( $rcObj, 
IContextSource $context ) {
+       public static function getScoreRecentChangesList( RecentChange $rcObj, 
IContextSource $context ) {
                $threshold = $rcObj->getAttribute( 'ores_damaging_threshold' );
                if ( $threshold === null ) {
                        $threshold = Hooks::getThreshold( 'damaging', 
$context->getUser(), $context->getTitle() );
diff --git a/includes/Parser/ScoreParser.php b/includes/Parser/ScoreParser.php
index 58c6079..7075d2a 100644
--- a/includes/Parser/ScoreParser.php
+++ b/includes/Parser/ScoreParser.php
@@ -63,13 +63,13 @@
        }
 
        /**
-        * @param $revision
-        * @param $model
-        * @param $modelOutputs
+        * @param int $revision
+        * @param string $model
+        * @param array[] $modelOutputs
         *
         * @return array
         */
-       private function processRevisionPerModel( $revision, $model, 
$modelOutputs ) {
+       private function processRevisionPerModel( $revision, $model, array 
$modelOutputs ) {
                $processedData = [];
                $prediction = $modelOutputs['score']['prediction'];
                // Kludge out booleans so we can match prediction against class 
name.
diff --git a/includes/ThresholdLookup.php b/includes/ThresholdLookup.php
index 87a0603..bb5c9f6 100644
--- a/includes/ThresholdLookup.php
+++ b/includes/ThresholdLookup.php
@@ -219,7 +219,7 @@
                }
        }
 
-       protected function extractKeyPath( $data, $keyPath ) {
+       protected function extractKeyPath( array $data, array $keyPath ) {
                $current = $data;
                foreach ( $keyPath as $key ) {
                        if ( !isset( $current[$key] ) ) {
@@ -231,7 +231,7 @@
                return $current;
        }
 
-       private function parseThresholds( $statsData, $model ) {
+       private function parseThresholds( array $statsData, $model ) {
                $thresholds = [];
                foreach ( $this->getFiltersConfig( $model ) as $levelName => 
$config ) {
                        if ( $config === false ) {
@@ -275,7 +275,7 @@
                return $thresholds;
        }
 
-       private function extractBoundValue( $levelName, $bound, $config, 
$statsData ) {
+       private function extractBoundValue( $levelName, $bound, $config, array 
$statsData ) {
                if ( is_numeric( $config ) ) {
                        return $config;
                }
diff --git a/includes/WatchedItemQueryServiceExtension.php 
b/includes/WatchedItemQueryServiceExtension.php
index e1350a5..48e5889 100644
--- a/includes/WatchedItemQueryServiceExtension.php
+++ b/includes/WatchedItemQueryServiceExtension.php
@@ -20,9 +20,9 @@
 
 use MediaWiki\MediaWikiServices;
 use ORES\Hooks\ApiHooksHandler;
-use ResultWrapper;
 use User;
 use Wikimedia\Rdbms\IDatabase;
+use Wikimedia\Rdbms\ResultWrapper;
 
 class WatchedItemQueryServiceExtension implements 
\WatchedItemQueryServiceExtension {
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I885bd7db8d635c3c76080bc8faaa805af3f8eaf2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Thiemo Kreuz (WMDE) <[email protected]>

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

Reply via email to