LanguageResultMatchFinder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 47
rs 10
c 0
b 0
f 0
ccs 13
cts 13
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A matchResultsToLanguage() 0 21 5
1
<?php
2
3
namespace SIL\Search;
4
5
use SIL\InterlanguageLinksLookup;
6
7
use SearchResultSet;
8
use Title;
9
10
/**
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class LanguageResultMatchFinder {
17
18
	/**
19
	 * @var InterlanguageLinksLookup|null
20
	 */
21
	private $interlanguageLinksLookup = null;
22
23
	/**
24
	 * @since 1.0
25
	 *
26
	 * @param InterlanguageLinksLookup $interlanguageLinksLookup
27
	 */
28 4
	public function __construct( InterlanguageLinksLookup $interlanguageLinksLookup ) {
29 4
		$this->interlanguageLinksLookup = $interlanguageLinksLookup;
30 4
	}
31
32
	/**
33
	 * @since 1.0
34
	 *
35
	 * @param SearchResultSet $matches
36
	 * @param $languageCode
37
	 *
38
	 * @return MappedSearchResultSet|null
39
	 */
40 3
	public function matchResultsToLanguage( SearchResultSet $matches, $languageCode ) {
41
42 3
		$mappedMatches = [];
43
44 3
		while ( $searchresult = $matches->next() ) {
45
46 2
			$title = $searchresult->getTitle();
47
48 2
			$pageLanguage = $this->interlanguageLinksLookup->findPageLanguageForTarget( $title );
49
50 2
			if ( $pageLanguage === $languageCode && $this->interlanguageLinksLookup->hasSilAnnotationFor( $title ) ) {
51 1
				$mappedMatches[] = $searchresult;
52
			}
53
		}
54
55 3
		if ( $mappedMatches === [] ) {
56 2
			return null;
57
		}
58
59 1
		return new MappedSearchResultSet( $mappedMatches, $matches->termMatches() );
60
	}
61
62
}
63