Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
10 / 10
ConfigExternalServicesFactory
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
10 / 10
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 getExternalServices
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
4 / 4
 getArrayForWikibaseConfiguredSparql
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
2 / 2
 getWikibaseConfiguredSparqlOrNull
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
<?php
namespace MediaWiki\Extension\WikibaseManifest;
use Config;
class ConfigExternalServicesFactory implements ExternalServicesFactory {
    private const WB_REPO_SETTINGS = 'WBRepoSettings';
    private const WB_REPO_SPARQL_ENDPOINT = 'sparqlEndpoint';
    /**
     * @var Config
     */
    private $config;
    /**
     * @var string
     */
    private $configMappingName;
    public function __construct( Config $config, string $configMappingName ) {
        $this->config = $config;
        $this->configMappingName = $configMappingName;
    }
    public function getExternalServices(): ExternalServices {
        return new ExternalServices(
            array_merge(
                $this->getArrayForWikibaseConfiguredSparql(),
                $this->config->get( $this->configMappingName )
            )
        );
    }
    private function getArrayForWikibaseConfiguredSparql() {
        $sparql = $this->getWikibaseConfiguredSparqlOrNull();
        return $sparql === null ? [] : [ ExternalServices::KEY_QUERYSERVICE => $sparql ];
    }
    private function getWikibaseConfiguredSparqlOrNull() {
        // TODO this might not exist as we can't define a dependency on Wikbase as it doesnt use
        // extension.json yet
        return $this->config->get( self::WB_REPO_SETTINGS )[self::WB_REPO_SPARQL_ENDPOINT] ?? null;
    }
}