Issues (31)

tests/Mock/Suggester.php (2 issues)

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
use Suilven\FreeTextSearch\Container\SuggesterResults;
13
14
class Suggester extends \Suilven\FreeTextSearch\Base\Suggester implements \Suilven\FreeTextSearch\Interfaces\Suggester
15
{
16
    /** @return array<string> */
17
    public function suggest(string $q, int $limit = 5): SuggesterResults
18
    {
19
        $result = new SuggesterResults();
20
        switch ($q) {
21
            case 'webmister':
22
                $result->setResults(['webmaster']);
23
24
                break;
25
        }
26
27
        $suggestions = $result->getResults();
28
        if (\sizeof($suggestions) > $limit) {
29
            $suggestions = \array_slice($result, 0, $limit);
0 ignored issues
show
$result of type Suilven\FreeTextSearch\Container\SuggesterResults is incompatible with the type array expected by parameter $array of array_slice(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
            $suggestions = \array_slice(/** @scrutinizer ignore-type */ $result, 0, $limit);
Loading history...
30
            $result->setResults($suggestions);
31
        }
32
33
        $result->setQuery($q);
34
        $result->setLimit($limit);
35
        $result->setIndex('unit_test_index');
36
37
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result returns the type Suilven\FreeTextSearch\Container\SuggesterResults which is incompatible with the documented return type string[].
Loading history...
38
    }
39
}
40