Completed
Push — master ( 598e28...b2a89a )
by mw
37:26 queued 36:17
created

MappedSearchResultSet   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 96
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A next() 0 19 6
A numRows() 0 3 1
A hasResults() 0 3 1
A getTotalHits() 0 3 1
A termMatches() 0 3 1
1
<?php
2
3
namespace SIL\Search;
4
5
use SearchResult;
6
use SearchResultSet;
7
8
use Title;
9
10
/**
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class MappedSearchResultSet extends SearchResultSet {
17
18
	/**
19
	 * @var SearchResult[]
20
	 */
21
	private $searchMatches = [];
22
23
	/**
24
	 * @var string[]
25
	 */
26
	private $termMatches;
27
28
	/**
29
	 * @var integer
30
	 */
31
	private $count;
32
33
	/**
34
	 * @since 1.0
35
	 *
36
	 * @param SearchResult[] $searchMatches
37
	 * @param array $termMatches
38
	 * @param integer $count
39
	 */
40
	public function __construct( $searchMatches, $termMatches, $count = 0 ) {
41
		$this->searchMatches = $searchMatches;
42
		$this->termMatches = $termMatches;
43
		$this->count = $count;
44
	}
45
46
	/**
47
	 * @since 1.0
48
	 *
49
	 * @return SearchResult|boolean
50
	 */
51
	public function next() {
52
53
		if ( $this->searchMatches === false || $this->searchMatches === [] ) {
54
			return false;
55
		}
56
57
		if ( ( list( $key, $match ) = each( $this->searchMatches ) ) !== false ) {
58
59
			if ( $match instanceOf SearchResult ) {
60
				return $match;
61
			}
62
63
			if ( $match instanceOf Title ) {
64
				return SearchResult::newFromTitle( $match );
65
			}
66
		}
67
68
		return false;
69
	}
70
71
	/**
72
	 * Return number of rows included in this result set.
73
	 *
74
	 * @since 1.0
75
	 *
76
	 * @return int|void
77
	 */
78
	public function numRows() {
79
		return count( $this->searchMatches );
80
	}
81
82
	/**
83
	 * Return true if results are included in this result set.
84
	 *
85
	 * @since 1.0
86
	 *
87
	 * @return bool
88
	 */
89
	public function hasResults() {
90
		return $this->numRows() > 0;
91
	}
92
93
	/**
94
	 * @since 1.0
95
	 *
96
	 * @return integer
97
	 */
98
	public function getTotalHits() {
99
		return $this->count;
100
	}
101
102
	/**
103
	 * @since 1.0
104
	 *
105
	 * @return string[]
106
	 */
107
	public function termMatches() {
108
		return $this->termMatches;
109
	}
110
111
}
112