Searcher   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
eloc 18
c 3
b 0
f 0
dl 0
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A searchForSimilar() 0 3 1
A search() 0 31 2
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
36
                $result->setPageSize(10);
37
                $result->setPage(1);
38
39
                $result->setIndex('unit_test_index');
40
                $result->setSuggestions(['fush']);
41
42
43
                $highlights = ['Title' => [
44
                    '<b>Fish</b>ing in New Zealand',
45
                    ],
46
                ];
47
48
                $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...
49
        }
50
51
        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...
52
    }
53
54
55
    /** @param \SilverStripe\ORM\DataObject $dataObject a dataObject relevant to the index */
56
    public function searchForSimilar(DataObject $dataObject): SearchResults
57
    {
58
        return $this->search('Fish');
59
    }
60
}
61