Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
11.11% |
2 / 18 |
|
16.67% |
1 / 6 |
CRAP | |
0.00% |
0 / 1 |
| BaseSearchResultSet | |
11.76% |
2 / 17 |
|
16.67% |
1 / 6 |
51.96 | |
0.00% |
0 / 1 |
| next | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| rewind | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| bcIterator | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| isApproximateTotalHits | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| termMatches | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| free | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Search; |
| 4 | |
| 5 | use ArrayIterator; |
| 6 | |
| 7 | /** |
| 8 | * BaseSearchResultSet is the base class that must be extended by SearchEngine |
| 9 | * search result set implementations. |
| 10 | * |
| 11 | * This base class is meant to hold B/C behaviors and to be useful it must never: |
| 12 | * - be used as type hints (ISearchResultSet must be used for this) |
| 13 | * - implement a constructor |
| 14 | * - declare utility methods |
| 15 | * |
| 16 | * @stable to extend |
| 17 | * @ingroup Search |
| 18 | * @method ArrayIterator getIterator() |
| 19 | */ |
| 20 | abstract class BaseSearchResultSet implements ISearchResultSet { |
| 21 | |
| 22 | /** |
| 23 | * @var ArrayIterator|null Iterator supporting BC iteration methods |
| 24 | */ |
| 25 | private $bcIterator; |
| 26 | |
| 27 | /** |
| 28 | * Fetches next search result, or false. |
| 29 | * @return SearchResult|false |
| 30 | * @deprecated since 1.32; Use self::extractResults() or foreach |
| 31 | */ |
| 32 | public function next() { |
| 33 | wfDeprecated( __METHOD__, '1.32' ); |
| 34 | $it = $this->bcIterator(); |
| 35 | $searchResult = $it->current(); |
| 36 | $it->next(); |
| 37 | return $searchResult ?? false; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Rewind result set back to beginning |
| 42 | * @deprecated since 1.32; Use self::extractResults() or foreach |
| 43 | */ |
| 44 | public function rewind() { |
| 45 | wfDeprecated( __METHOD__, '1.32' ); |
| 46 | $this->bcIterator()->rewind(); |
| 47 | } |
| 48 | |
| 49 | private function bcIterator(): ArrayIterator { |
| 50 | if ( $this->bcIterator === null ) { |
| 51 | // @phan-suppress-next-line PhanTypeMismatchProperty Expected |
| 52 | $this->bcIterator = 'RECURSION'; |
| 53 | $this->bcIterator = $this->getIterator(); |
| 54 | } elseif ( $this->bcIterator === 'RECURSION' ) { |
| 55 | // @phan-suppress-previous-line PhanTypeComparisonFromArray Use of string is a hack |
| 56 | // Either next/rewind or extractResults must be implemented. This |
| 57 | // class was potentially instantiated directly. It should be |
| 58 | // abstract with abstract methods to enforce this but that's a |
| 59 | // breaking change... |
| 60 | wfDeprecated( static::class . ' without implementing extractResults', '1.32' ); |
| 61 | $this->bcIterator = new ArrayIterator( [] ); |
| 62 | } |
| 63 | return $this->bcIterator; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @inheritDoc |
| 68 | */ |
| 69 | public function isApproximateTotalHits(): bool { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Fetch an array of regular expression fragments for matching |
| 75 | * the search terms as parsed by this engine in a text extract. |
| 76 | * STUB |
| 77 | * |
| 78 | * @return string[] |
| 79 | * @deprecated since 1.34 (use SqlSearchResult) |
| 80 | */ |
| 81 | public function termMatches() { |
| 82 | return []; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Frees the result set, if applicable. |
| 87 | * @deprecated since 1.34; noop |
| 88 | */ |
| 89 | public function free() { |
| 90 | } |
| 91 | } |
| 92 | /** @deprecated class alias since 1.46 */ |
| 93 | class_alias( BaseSearchResultSet::class, 'BaseSearchResultSet' ); |