Ladsgroup has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/394760 )

Change subject: Rename Stats to ThresholdLookup and make it a service
......................................................................

Rename Stats to ThresholdLookup and make it a service

The only public method in this class is getThresholds

Bug: T181892
Change-Id: I03b9c654deb90b0a1f0bc87d33aa5dfd4f797745
---
M extension.json
M includes/Hooks.php
M includes/Hooks/ChangesListHooksHandler.php
M includes/ServiceWiring.php
R includes/ThresholdLookup.php
M maintenance/DumpThresholds.php
M tests/phpunit/includes/ServiceWiringTest.php
R tests/phpunit/includes/ThresholdLookupTest.php
8 files changed, 29 insertions(+), 27 deletions(-)


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

diff --git a/extension.json b/extension.json
index df8881e..0310457 100644
--- a/extension.json
+++ b/extension.json
@@ -19,7 +19,7 @@
                "ORES\\FetchScoreJob": "includes/FetchScoreJob.php",
                "ORES\\Range": "includes/Range.php",
                "ORES\\Scoring": "includes/Scoring.php",
-               "ORES\\Stats": "includes/Stats.php",
+               "ORES\\ThresholdLookup": "includes/ThresholdLookup.php",
                "ORES\\Storage\\ModelLookup": 
"includes/Storage/ModelLookup.php",
                "ORES\\Storage\\SqlModelLookup": 
"includes/Storage/SqlModelLookup.php",
                "ORES\\ApiQueryORES": "includes/ApiQueryORES.php",
diff --git a/includes/Hooks.php b/includes/Hooks.php
index e0a743c..cdb8c59 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -22,6 +22,7 @@
 use JobQueueGroup;
 use IContextSource;
 use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
 use OutputPage;
 use RecentChange;
 use RequestContext;
@@ -189,7 +190,7 @@
        }
 
        public static function getDamagingThresholds() {
-               $stats = Stats::newFromGlobalState();
+               $stats = MediaWikiServices::getInstance()->getService( 
'ORESThresholdLookup' );
                $thresholds = [];
                foreach ( $stats->getThresholds( 'damaging' ) as $name => 
$bounds ) {
                        $thresholds[ $name ] = $bounds[ 'min' ];
diff --git a/includes/Hooks/ChangesListHooksHandler.php 
b/includes/Hooks/ChangesListHooksHandler.php
index f3bf99d..93c7d79 100644
--- a/includes/Hooks/ChangesListHooksHandler.php
+++ b/includes/Hooks/ChangesListHooksHandler.php
@@ -23,9 +23,9 @@
 use EnhancedChangesList;
 use FormOptions;
 use IContextSource;
+use MediaWiki\MediaWikiServices;
 use ORES\Hooks;
 use ORES\Range;
-use ORES\Stats;
 use RCCacheEntry;
 use RecentChange;
 use SpecialRecentChanges;
@@ -43,7 +43,7 @@
                        return;
                }
 
-               $stats = Stats::newFromGlobalState();
+               $stats = MediaWikiServices::getInstance()->getService( 
'ORESThresholdLookup' );
 
                $changeTypeGroup = $clsp->getFilterGroup( 'changeType' );
                $logFilter = $changeTypeGroup->getFilter( 'hidelog' );
@@ -538,7 +538,7 @@
        }
 
        private static function buildRangeFilter( $name, $filterValue ) {
-               $stats = Stats::newFromGlobalState();
+               $stats = MediaWikiServices::getInstance()->getService( 
'ORESThresholdLookup' );
                $thresholds = $stats->getThresholds( $name );
 
                $selectedLevels = is_array( $filterValue ) ? $filterValue :
diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php
index fc59bf0..458c902 100644
--- a/includes/ServiceWiring.php
+++ b/includes/ServiceWiring.php
@@ -16,6 +16,7 @@
 
 namespace ORES;
 
+use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\MediaWikiServices;
 use ORES\Storage\SqlModelLookup;
 
@@ -23,4 +24,13 @@
        'ORESModelLookup' => function ( MediaWikiServices $services ) {
                return new SqlModelLookup( $services->getDBLoadBalancer() );
        },
+
+       'ORESThresholdLookup' => function ( MediaWikiServices $services ) {
+               return new ThresholdLookup(
+                       Api::newFromContext(),
+                       $services->getMainWANObjectCache(),
+                       LoggerFactory::getInstance( 'ORES' )
+               );
+       }
+
 ];
diff --git a/includes/Stats.php b/includes/ThresholdLookup.php
similarity index 95%
rename from includes/Stats.php
rename to includes/ThresholdLookup.php
index 2b9922b..87a0603 100644
--- a/includes/Stats.php
+++ b/includes/ThresholdLookup.php
@@ -16,12 +16,11 @@
 
 namespace ORES;
 
-use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\MediaWikiServices;
 use Psr\Log\LoggerInterface;
 use WANObjectCache;
 
-class Stats {
+class ThresholdLookup {
 
        /**
         * @var Api
@@ -29,7 +28,7 @@
        private $api;
 
        /**
-        * @var \WANObjectCache
+        * @var WANObjectCache
         */
        private $cache;
 
@@ -40,7 +39,7 @@
 
        /**
         * @param Api $api
-        * @param \WANObjectCache $cache
+        * @param WANObjectCache $cache
         * @param LoggerInterface $logger
         */
        public function __construct( Api $api, WANObjectCache $cache, 
LoggerInterface $logger ) {
@@ -297,17 +296,6 @@
                }
 
                return null;
-       }
-
-       /**
-        * @return self
-        */
-       public static function newFromGlobalState() {
-               return new self(
-                       Api::newFromContext(),
-                       
MediaWikiServices::getInstance()->getMainWANObjectCache(),
-                       LoggerFactory::getInstance( 'ORES' )
-               );
        }
 
 }
diff --git a/maintenance/DumpThresholds.php b/maintenance/DumpThresholds.php
index c96aa3a..3e0de39 100644
--- a/maintenance/DumpThresholds.php
+++ b/maintenance/DumpThresholds.php
@@ -3,6 +3,7 @@
 namespace ORES;
 
 use Maintenance;
+use MediaWiki\MediaWikiServices;
 
 require_once getenv( 'MW_INSTALL_PATH' ) !== false
        ? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
@@ -22,7 +23,7 @@
        public function execute() {
                $this->output( "Starting..." );
                $models = $this->getModels();
-               $stats = Stats::newFromGlobalState();
+               $stats = MediaWikiServices::getInstance()->getService( 
'ORESThresholdLookup' );
 
                foreach ( $models as $name => $info ) {
                        $this->output( "\n$name\n" );
diff --git a/tests/phpunit/includes/ServiceWiringTest.php 
b/tests/phpunit/includes/ServiceWiringTest.php
index 39dca71..70e1a5e 100644
--- a/tests/phpunit/includes/ServiceWiringTest.php
+++ b/tests/phpunit/includes/ServiceWiringTest.php
@@ -4,6 +4,7 @@
 
 use MediaWiki\MediaWikiServices;
 use ORES\Storage\ModelLookup;
+use ORES\ThresholdLookup;
 
 /**
  * @covers ServiceWiring.php
@@ -17,6 +18,7 @@
        public function provideServices() {
                return [
                        [ 'ORESModelLookup', ModelLookup::class ],
+                       [ 'ORESThresholdLookup', ThresholdLookup::class ]
                ];
        }
 
diff --git a/tests/phpunit/includes/StatsTest.php 
b/tests/phpunit/includes/ThresholdLookupTest.php
similarity index 93%
rename from tests/phpunit/includes/StatsTest.php
rename to tests/phpunit/includes/ThresholdLookupTest.php
index f1cd32f..34589a8 100644
--- a/tests/phpunit/includes/StatsTest.php
+++ b/tests/phpunit/includes/ThresholdLookupTest.php
@@ -10,9 +10,9 @@
 
 /**
  * @group ORES
- * @covers ORES\Stats
+ * @covers ORES\ThresholdLookup
  */
-class StatsTest extends \MediaWikiTestCase {
+class ThresholdLookupTest extends \MediaWikiTestCase {
 
        protected function setUp() {
                parent::setUp();
@@ -41,7 +41,7 @@
        public function testGetThresholds_modelConfigNotFound() {
                $api = $this->getMockBuilder( Api::class )->getMock();
                $logger = $this->getLoggerMock();
-               $stats = new ORES\Stats( $api, WANObjectCache::newEmpty(), 
$logger );
+               $stats = new ORES\ThresholdLookup( $api, 
WANObjectCache::newEmpty(), $logger );
 
                $thresholds = $stats->getThresholds( 'unknown_model' );
 
@@ -77,7 +77,7 @@
                // FIXME: Review and check for logging.
                // $logger->expects( $this->exactly( 2 ) )->method( 'warning' );
 
-               $stats = new ORES\Stats( $api, WANObjectCache::newEmpty(), 
$logger );
+               $stats = new ORES\ThresholdLookup( $api, 
WANObjectCache::newEmpty(), $logger );
 
                $thresholds = $stats->getThresholds( 'goodfaith' );
 
@@ -122,7 +122,7 @@
                                        ],
                        ] ] ] ] ] ] );
 
-               $stats = new ORES\Stats(
+               $stats = new ORES\ThresholdLookup(
                        $api,
                        WANObjectCache::newEmpty(),
                        LoggerFactory::getInstance( 'test' )
@@ -184,7 +184,7 @@
                                        ],
                        ] ] ] ] ] ] );
 
-               $stats = new ORES\Stats(
+               $stats = new ORES\ThresholdLookup(
                        $api,
                        WANObjectCache::newEmpty(),
                        LoggerFactory::getInstance( 'test' )

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I03b9c654deb90b0a1f0bc87d33aa5dfd4f797745
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to