Debian Codegraph @

includes/search/FauxSearchResultSet.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Title\Title;
4
5 /**
6 * A manually constructed search result set.
7 * Mainly meant for supporting developer setups where the search operation might be
8 * mocked or proxied.
9 */
10 class FauxSearchResultSet extends SearchResultSet {
11
12 /**
13 * @var int|null
14 * @see getTotalHits
15 */
16 private $totalHits;
17
18 /**
19 * @param array<Title|SearchResult> $results Search results
20 * @param int|null $totalHits See getTotalHits()
21 */
22 public function __construct( array $results, $totalHits = null ) {
23 $totalHits = max( count( $results ), $totalHits );
24 $hasMoreResults = count( $results ) < $totalHits;
25 parent::__construct( false, $hasMoreResults );
26 $this->results = array_map( static function ( $result ) {
27 if ( $result instanceof SearchResult ) {
28 return $result;
29 } elseif ( $result instanceof Title ) {
30 return new FauxSearchResult( $result );
31 } else {
32 throw new InvalidArgumentException( '$results must contain Title or SearchResult' );
33 }
34 }, $results );
35 $this->totalHits = $totalHits;
36 }
37
38 /** @inheritDoc */
39 public function getTotalHits() {
40 return $this->totalHits;
41 }
42
43 }