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