jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/400402 )
Change subject: Add strict type hints to production code
......................................................................
Add strict type hints to production 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/ThresholdParser.php
M includes/WatchedItemQueryServiceExtension.php
M maintenance/PurgeScoreCache.php
9 files changed, 39 insertions(+), 25 deletions(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
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 976fb89..7c9a391 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;
}
@@ -92,7 +92,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..927fd69 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,12 @@
* @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 +476,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 +505,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 626c291..957c9f5 100644
--- a/includes/ThresholdLookup.php
+++ b/includes/ThresholdLookup.php
@@ -177,7 +177,7 @@
return $resultMap;
}
- protected function extractKeyPath( $data, $keyPath ) {
+ protected function extractKeyPath( array $data, array $keyPath ) {
$current = $data;
foreach ( $keyPath as $key ) {
if ( !isset( $current[$key] ) ) {
@@ -186,7 +186,6 @@
}
$current = $current[$key];
}
-
return $current;
}
diff --git a/includes/ThresholdParser.php b/includes/ThresholdParser.php
index e304ade..54e8716 100644
--- a/includes/ThresholdParser.php
+++ b/includes/ThresholdParser.php
@@ -30,7 +30,7 @@
$this->logger = $logger;
}
- public function parseThresholds( $statsData, $model ) {
+ public function parseThresholds( array $statsData, $model ) {
$thresholds = [];
foreach ( $this->getFiltersConfig( $model ) as $levelName =>
$config ) {
if ( $config === false ) {
@@ -65,6 +65,11 @@
return $thresholds;
}
+ /**
+ * @param string $model
+ *
+ * @return array|bool
+ */
public function getFiltersConfig( $model ) {
global $wgOresFiltersThresholds;
if ( !isset( $wgOresFiltersThresholds[$model] ) ) {
@@ -110,7 +115,7 @@
}
}
- private function extractBoundValue( $bound, $config, $statsData ) {
+ private function extractBoundValue( $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 {
diff --git a/maintenance/PurgeScoreCache.php b/maintenance/PurgeScoreCache.php
index 0405e37..7882781 100644
--- a/maintenance/PurgeScoreCache.php
+++ b/maintenance/PurgeScoreCache.php
@@ -116,7 +116,12 @@
* @return int The number of deleted rows
* @see Database::select
*/
- private function deleteRows( $tables, $conditions, $join_conds,
$batchSize = 1000 ) {
+ private function deleteRows(
+ array $tables,
+ array $conditions,
+ array $join_conds,
+ $batchSize = 1000
+ ) {
$dbr = \wfGetDB( DB_REPLICA );
$dbw = \wfGetDB( DB_MASTER );
--
To view, visit https://gerrit.wikimedia.org/r/400402
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I885bd7db8d635c3c76080bc8faaa805af3f8eaf2
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Thiemo Kreuz (WMDE) <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits