Passed
Push — master ( 76df74...7115c3 )
by Gordon
02:05
created

Searcher::searchForSimilar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php declare(strict_types = 1);
2
3
/**
4
 * Created by PhpStorm.
5
 * User: gordon
6
 * Date: 24/3/2561
7
 * Time: 20:36 น.
8
 */
9
10
namespace Suilven\FreeTextSearch\Tests\Mock;
11
12
// @phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
13
14
use SilverStripe\ORM\ArrayList;
15
use SilverStripe\ORM\DataObject;
16
use Suilven\FreeTextSearch\Container\SearchResults;
17
18
class Searcher extends \Suilven\FreeTextSearch\Base\Searcher
19
{
20
    /** @return array<string,array<string,string>> */
21
    public function search(?string $q): SearchResults
22
    {
23
        $result = new SearchResults();
24
        switch ($q) {
25
            case 'Fish':
26
                $records = [
27
                    [
28
                        'Title' => 'Fishing in New Zealand',
29
                    ],
30
                ];
31
                $recordsList = new ArrayList($records);
32
                $result->setRecords($recordsList);
33
34
                $result->setTime(0.017);
35
                $result->setFacets([]);
36
37
                $result->setPageSize(10);
38
                $result->setPage(1);
39
40
                $result->setIndex('unit_test_index');
41
                $result->setSuggestions(['fush']);
42
43
44
                $highlights = ['Title' => [
45
                    '<b>Fish</b>ing in New Zealand',
46
                    ],
47
                ];
48
49
                $result->Highlights = $highlights;
0 ignored issues
show
Bug introduced by
The property Highlights does not seem to exist on Suilven\FreeTextSearch\Container\SearchResults.
Loading history...
50
        }
51
52
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result returns the type Suilven\FreeTextSearch\Container\SearchResults which is incompatible with the documented return type array<string,array<string,string>>.
Loading history...
53
    }
54
55
56
    /** @param \SilverStripe\ORM\DataObject $dataObject a dataObject relevant to the index */
57
    public function searchForSimilar(DataObject $dataObject): SearchResults
58
    {
59
        return $this->search('Fish');
60
    }
61
}
62