DynamicInterwikiPrefixLoader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 52
rs 10
c 0
b 0
f 0
ccs 17
cts 17
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isEnabledPrefixForExternalRepository() 0 3 1
A tryToLoadIwMapForExternalRepository() 0 19 2
1
<?php
2
3
namespace SEQL;
4
5
/**
6
 * Allows to dynamically assign interwiki prefixes without having to
7
 * create an interwiki table entry.
8
 *
9
 * @license GNU GPL v2+
10
 * @since 1.0
11
 *
12
 * @author mwjames
13
 */
14
class DynamicInterwikiPrefixLoader {
15
16
	/**
17
	 * @var array
18
	 */
19
	private $enabledExternalRepositoryEndpoints = array();
20
21
	/**
22
	 * @since 1.0
23
	 *
24
	 * @param array $enabledExternalRepositoryEndpoints
25
	 */
26 11
	public function __construct( array $enabledExternalRepositoryEndpoints = array() ) {
27 11
		$this->enabledExternalRepositoryEndpoints = $enabledExternalRepositoryEndpoints;
28 11
	}
29
30
	/**
31
	 * @since 1.0
32
	 *
33
	 * @param string $prefix
34
	 */
35 3
	public function isEnabledPrefixForExternalRepository( $prefix ) {
36 3
		return isset( $this->enabledExternalRepositoryEndpoints[$prefix] );
37
	}
38
39
	/**
40
	 * @since 1.0
41
	 *
42
	 * @param string $prefix
43
	 * @param array &$interwiki
44
	 */
45 3
	public function tryToLoadIwMapForExternalRepository( $prefix, &$interwiki ) {
46
47 3
		if ( !$this->isEnabledPrefixForExternalRepository( $prefix ) ) {
48 2
			return true;
49
		}
50
51 2
		list( $iw_url, $iw_api, $iw_local ) = $this->enabledExternalRepositoryEndpoints[$prefix];
52
53
		$interwiki = array(
54 2
			'iw_prefix' => $prefix,
55 2
			'iw_url'    => $iw_url,
56 2
			'iw_api'    => $iw_api,
57 2
			'iw_wikiid' => $prefix,
58 2
			'iw_local'  => $iw_local,
59 2
			'iw_trans'  => false,
60 2
		);
61
62 2
		return false;
63
	}
64
65
}
66