Total Complexity | 6 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
9 | class ResponseParser extends ResponseParserAbstract implements ResponseParserInterface |
||
|
|||
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) |
||
53 | ); |
||
54 | } |
||
55 | } |