InterwikiLanguageLinkFetcher   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 51
rs 10
c 0
b 0
f 0
ccs 18
cts 18
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addAnnotationForInterwikiLanguageLink() 0 12 2
A fetchLanguagelinksFromParserOutput() 0 15 5
1
<?php
2
3
namespace SIL;
4
5
use ParserOutput;
6
7
/**
8
 * @license GNU GPL v2+
9
 * @since 1.0
10
 *
11
 * @author mwjames
12
 */
13
class InterwikiLanguageLinkFetcher {
14
15
	/**
16
	 * @var LanguageLinkAnnotator
17
	 */
18
	private $languageLinkAnnotator;
19
20
	/**
21
	 * @since 1.0
22
	 *
23
	 * @param LanguageLinkAnnotator $languageLinkAnnotator
24
	 */
25 7
	public function __construct( LanguageLinkAnnotator $languageLinkAnnotator ) {
26 7
		$this->languageLinkAnnotator = $languageLinkAnnotator;
27 7
	}
28
29
	/**
30
	 * @since 1.0
31
	 *
32
	 * @return ParserOutput $parserOutput
33
	 */
34 6
	public function fetchLanguagelinksFromParserOutput( ParserOutput $parserOutput ) {
35
36 6
		if ( $parserOutput->getLanguageLinks() === [] || $parserOutput->getLanguageLinks() === null ) {
37 3
			return;
38
		}
39
40 5
		foreach ( $parserOutput->getLanguageLinks() as $languageLink ) {
41
42 5
			if ( strpos( $languageLink, 'sil:' ) !== false ) {
43 3
				continue;
44
			}
45
46 2
			$this->addAnnotationForInterwikiLanguageLink( $languageLink );
47
		}
48 5
	}
49
50 2
	private function addAnnotationForInterwikiLanguageLink( $languageLink ) {
51
52 2
		$interwikiLanguageLink = new InterwikiLanguageLink( $languageLink );
53
54 2
		if ( $interwikiLanguageLink->getLanguageCode() === '' ) {
55 1
			return;
56
		}
57
58 1
		$this->languageLinkAnnotator->addAnnotationForInterwikiLanguageLink(
59 1
			$interwikiLanguageLink
60
		);
61 1
	}
62
63
}
64