Passed
Pull Request — master (#4)
by Gordon
08:08
created

Suggester::suggest()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 15
rs 10
cc 3
nc 4
nop 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
class Suggester extends \Suilven\FreeTextSearch\Base\Suggester implements \Suilven\FreeTextSearch\Interfaces\Suggester
13
{
14
    /** @return array<string> */
15
    public function suggest(string $q, int $limit = 5): array
16
    {
17
        $result = 'unknown';
18
        switch ($q) {
19
            case 'webmister':
20
                $result = 'webmaster';
21
22
                break;
23
        }
24
25
        if (\sizeof($result) > $limit) {
0 ignored issues
show
Bug introduced by
$result of type string is incompatible with the type Countable|array expected by parameter $var of sizeof(). ( Ignorable by Annotation )

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

25
        if (\sizeof(/** @scrutinizer ignore-type */ $result) > $limit) {
Loading history...
26
            $result = \array_slice($result, 0, $limit);
0 ignored issues
show
Bug introduced by
$result of type string 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

26
            $result = \array_slice(/** @scrutinizer ignore-type */ $result, 0, $limit);
Loading history...
27
        }
28
29
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result could return the type string which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
30
    }
31
}
32