Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
TotalTableCountMetric
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 calculate
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 getStatsdKey
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace MediaWiki\Extension\MediaModeration\PeriodicMetrics;
4
5use Wikimedia\Rdbms\IReadableDatabase;
6
7/**
8 * A metric that holds the total table count of the mediamoderation_scan table
9 * for a given wiki.
10 */
11class TotalTableCountMetric implements IMetric {
12
13    private IReadableDatabase $dbr;
14
15    /**
16     * @param IReadableDatabase $dbr
17     */
18    public function __construct( IReadableDatabase $dbr ) {
19        $this->dbr = $dbr;
20    }
21
22    /** @inheritDoc */
23    public function calculate(): int {
24        return $this->dbr->newSelectQueryBuilder()
25            ->select( 'COUNT(*)' )
26            ->from( 'mediamoderation_scan' )
27            ->caller( __METHOD__ )
28            ->fetchField();
29    }
30
31    /** @inheritDoc */
32    public function getStatsdKey(): string {
33        return 'MediaModeration.ScanTable.TotalCount';
34    }
35}