Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
91.67% covered (success)
91.67%
11 / 12
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CirrusConfigInterwikiResolver
91.67% covered (success)
91.67%
11 / 12
50.00% covered (danger)
50.00%
1 / 2
4.01
0.00% covered (danger)
0.00%
0 / 1
 accepts
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
3.07
 loadMatrix
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace CirrusSearch;
4
5/**
6 * InterwikiResolver suited for custom cirrus config:
7 * - wgCirrusSearchLanguageToWikiMap: a map of language code to wiki db prefixes
8 * - wgCirrusSearchInterwikiSources: a map of cross project interwiki prefixes to wikiId
9 * - wgCirrusSearchWikiToNameMap: a map of language interwiki prefixes to wikiId
10 */
11
12class CirrusConfigInterwikiResolver extends BaseInterwikiResolver {
13    /**
14     * @param SearchConfig $config
15     * @return bool true if this resolver can run with the specified config
16     */
17    public static function accepts( SearchConfig $config ) {
18        if ( !empty( $config->get( 'CirrusSearchInterwikiSources' ) ) ) {
19            return true;
20        }
21        if ( !empty( $config->get( 'CirrusSearchWikiToNameMap' ) ) ) {
22            return true;
23        }
24        return false;
25    }
26
27    protected function loadMatrix() {
28        $sisterProjects = $this->config->get( 'CirrusSearchInterwikiSources' ) ?? [];
29        $languageMap = $this->config->get( 'CirrusSearchLanguageToWikiMap' ) ?? [];
30        $crossLanguage = $this->config->get( 'CirrusSearchWikiToNameMap' ) ?? [];
31        $crossLanguage = array_filter( $crossLanguage, function ( $entry ) {
32            return $entry !== $this->config->getWikiId();
33        } );
34        $prefixesByWiki = array_flip( $sisterProjects ) + array_flip( $crossLanguage );
35        return [
36            'sister_projects' => $sisterProjects,
37            'language_map' => $languageMap,
38            'cross_language' => $crossLanguage,
39            'prefixes_by_wiki' => $prefixesByWiki,
40        ];
41    }
42}