AbstractSuggester   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 28
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A suggestByFields() 0 13 3
1
<?php
2
3
namespace Mdiyakov\DoctrineSolrBundle\Suggester;
4
5
use Mdiyakov\DoctrineSolrBundle\Query\Suggest\AbstractSuggestQuery;
6
use Mdiyakov\DoctrineSolrBundle\Query\Suggest\Result\Result;
7
8
abstract class AbstractSuggester
9
{
10
11
    /**
12
     * @return AbstractSuggestQuery
13
     */
14
    abstract protected function getQuery();
15
16
17
    /**
18
     * @param string $searchTerm
19
     * @param string[] $fields
20
     * @param int $limit
21
     * @return Result
22
     */
23
    public function suggestByFields($searchTerm, $fields, $limit = 10)
24
    {
25
        $query = $this->getQuery();
26
        $query->setTerm($searchTerm);
27
        $query->setCount($limit);
28
29
        if (is_array($fields)) {
0 ignored issues
show
introduced by
The condition is_array($fields) is always true.
Loading history...
30
            foreach ($fields as $field) {
31
                $query->addField($field);
32
            }
33
        }
34
35
        return $query->suggest();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->suggest() returns the type Solarium\Core\Query\Result\ResultInterface which is incompatible with the documented return type Mdiyakov\DoctrineSolrBun...y\Suggest\Result\Result.
Loading history...
36
    }
37
}