Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
ConfigExternalServicesFactory
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getExternalServices
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 getArrayForWikibaseConfiguredSparql
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getWikibaseConfiguredSparqlOrNull
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace MediaWiki\Extension\WikibaseManifest;
4
5use Config;
6
7class ConfigExternalServicesFactory implements ExternalServicesFactory {
8    private const WB_REPO_SETTINGS = 'WBRepoSettings';
9    private const WB_REPO_SPARQL_ENDPOINT = 'sparqlEndpoint';
10
11    /**
12     * @var Config
13     */
14    private $config;
15
16    /**
17     * @var string
18     */
19    private $configMappingName;
20
21    public function __construct( Config $config, string $configMappingName ) {
22        $this->config = $config;
23        $this->configMappingName = $configMappingName;
24    }
25
26    public function getExternalServices(): ExternalServices {
27        return new ExternalServices(
28            array_merge(
29                $this->getArrayForWikibaseConfiguredSparql(),
30                $this->config->get( $this->configMappingName )
31            )
32        );
33    }
34
35    private function getArrayForWikibaseConfiguredSparql() {
36        $sparql = $this->getWikibaseConfiguredSparqlOrNull();
37        return $sparql === null ? [] : [ ExternalServices::KEY_QUERYSERVICE => $sparql ];
38    }
39
40    private function getWikibaseConfiguredSparqlOrNull() {
41        // TODO this might not exist as we can't define a dependency on Wikbase as it doesnt use
42        // extension.json yet
43        return $this->config->get( self::WB_REPO_SETTINGS )[self::WB_REPO_SPARQL_ENDPOINT] ?? null;
44    }
45}