ResponseParser::parse()   A
last analyzed

Complexity

Conditions 5
Paths 2

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.2568
c 0
b 0
f 0
cc 5
nc 2
nop 1
1
<?php
2
3
namespace Mdiyakov\DoctrineSolrBundle\Query\Suggest\Solarium;
4
5
use Solarium\Core\Query\ResponseParser as ResponseParserAbstract;
6
use Solarium\Core\Query\ResponseParserInterface as ResponseParserInterface;
7
use Solarium\QueryType\Suggester\Result\Result;
8
9
class ResponseParser  extends ResponseParserAbstract implements ResponseParserInterface
0 ignored issues
show
Deprecated Code introduced by
The class Solarium\Core\Query\ResponseParser has been deprecated. ( Ignorable by Annotation )

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

9
class ResponseParser  extends /** @scrutinizer ignore-deprecated */ ResponseParserAbstract implements ResponseParserInterface
Loading history...
10
{
11
    /**
12
     * Get result data for the response
13
     *
14
     * @param  Result $result
15
     * @return array
16
     */
17
    public function parse($result)
18
    {
19
        $data = $result->getData();
20
        $query = $result->getQuery();
21
        $suggestions = array();
22
23
        if (isset($data['suggest']) && is_array($data['suggest'])) {
24
25
            $suggestResults = $data['suggest'];
26
            $termClass = $query->getOption('termclass');
27
            foreach ($suggestResults as $dictionary => $termData) {
28
29
                foreach ($termData as $term => $suggestionData) {
30
                    $suggestions[$dictionary][$term] = $this->createTerm($termClass, $suggestionData);
31
                }
32
            }
33
        }
34
35
        return $this->addHeaderInfo(
36
            $data,
37
            array(
38
                'results' => $suggestions,
39
            )
40
        );
41
    }
42
43
    /**
44
     * @param $termClass
45
     * @param array $suggestionData
46
     * @return mixed
47
     */
48
    private function createTerm($termClass, array $suggestionData)
49
    {
50
        return new $termClass(
51
            $suggestionData['numFound'],
52
            $suggestionData['suggestions']
53
        );
54
    }
55
}