Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
TranslationStatsBase
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 6
210
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 indexOf
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 labels
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDateFormat
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
30
 makeTimeCondition
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
 namespacesFromGroups
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\Statistics;
5
6use MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups;
7use Wikimedia\Rdbms\IDatabase;
8
9/**
10 * Provides some hand default implementations for TranslationStatsInterface.
11 * @ingroup Stats
12 * @license GPL-2.0-or-later
13 * @since 2010.07
14 */
15abstract class TranslationStatsBase implements TranslationStatsInterface {
16    protected TranslationStatsGraphOptions $opts;
17
18    public function __construct( TranslationStatsGraphOptions $opts ) {
19        $this->opts = $opts;
20    }
21
22    public function indexOf( $row ) {
23        return [ 'all' ];
24    }
25
26    public function labels() {
27        return [ 'all' ];
28    }
29
30    public function getDateFormat() {
31        $dateFormat = 'Y-m-d';
32        $scale = $this->opts->getValue( 'scale' );
33        if ( $scale === 'years' ) {
34            $dateFormat = 'Y';
35        } elseif ( $scale === 'months' ) {
36            $dateFormat = 'Y-m';
37        } elseif ( $scale === 'weeks' ) {
38            $dateFormat = 'Y-\WW';
39        } elseif ( $scale === 'hours' ) {
40            $dateFormat .= ';H';
41        }
42
43        return $dateFormat;
44    }
45
46    protected static function makeTimeCondition( IDatabase $database, $field, $start, $end ) {
47        $conds = [];
48        if ( $start !== null ) {
49            $conds[] = "$field >= " . $database->addQuotes( $database->timestamp( $start ) );
50        }
51        if ( $end !== null ) {
52            $conds[] = "$field <= " . $database->addQuotes( $database->timestamp( $end ) );
53        }
54
55        return $conds;
56    }
57
58    /**
59     * @since 2012-03-05
60     * @param array $groupIds
61     * @return array
62     */
63    protected static function namespacesFromGroups( $groupIds ) {
64        $namespaces = [];
65        foreach ( $groupIds as $id ) {
66            $group = MessageGroups::getGroup( $id );
67            if ( $group ) {
68                $namespace = $group->getNamespace();
69                $namespaces[$namespace] = true;
70            }
71        }
72
73        return array_keys( $namespaces );
74    }
75}