Passed
Push — master ( 15347e...e929c7 )
by
unknown
02:05
created

SqlToArray   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 53
c 3
b 0
f 0
dl 0
loc 71
rs 10
wmc 25

1 Method

Rating   Name   Duplication   Size   Complexity  
D getResponse() 0 69 25
1
<?php
2
3
namespace Manticoresearch\Response;
4
5
use Manticoresearch\Response;
6
7
class SqlToArray extends Response
8
{
9
    public function getResponse()
10
    {
11
        $response = parent::getResponse();
12
        if (isset($response['columns'], $response['data'])) {
13
            $data = [];
14
            array_walk($response['columns'], static function (&$value, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

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

14
            array_walk($response['columns'], static function (&$value, /** @scrutinizer ignore-unused */ $key) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
15
                $value = array_keys($value)[0];
16
            });
17
            $id = -1;
18
            foreach ($response['data'] as $property) {
19
                if (isset($property['id'])) {
20
                    $id = $property['id'];
21
                    if (count($property) > 1) {
22
                        unset($property['id']);
23
                    }
24
                } elseif (isset($this->params['customMapping']) and $this->params['customMapping']) {
25
                    if (isset($property['Field'])) {
26
                        $id = $property['Field'];
27
                        if (count($property) > 1) {
28
                            unset($property['Field']);
29
                        }
30
                    } elseif (isset($property['Variable_name'])) {
31
                        $id = $property['Variable_name'];
32
                        if (count($property) > 1) {
33
                            unset($property['Variable_name']);
34
                        }
35
                    } elseif (isset($property['Index'])) {
36
                        $id = $property['Index'];
37
                        if (count($property) > 1) {
38
                            unset($property['Index']);
39
                        }
40
                    } elseif (isset($property['Counter'])) {
41
                        $id = $property['Counter'];
42
                        if (count($property) > 1) {
43
                            unset($property['Counter']);
44
                        }
45
                    } elseif (isset($property['Key'])) {
46
                        $id = $property['Key'];
47
                        if (count($property) > 1) {
48
                            unset($property['Key']);
49
                        }
50
                    } elseif (isset($property['command'])) {
51
                        $id = $property['command'];
52
                        if (count($property) > 1) {
53
                            unset($property['command']);
54
                        }
55
                    } elseif (isset($property['suggest'])) {
56
                        $id = $property['suggest'];
57
                        if (count($property) > 1) {
58
                            unset($property['suggest']);
59
                        }
60
                    } elseif (isset($property['Variable'])) {
61
                        $id = $property['Variable'];
62
                        if (count($property) > 1) {
63
                            unset($property['Variable']);
64
                        }
65
                    } else {
66
                        $id++;
67
                    }
68
                } else {
69
                    $id++;
70
                }
71
                $data[$id] = (count($property) == 1)?array_shift($property):$property;
72
            }
73
            if (count($data) > 0) {
74
                return $data;
75
            }
76
        }
77
        return $response;
78
    }
79
}
80