Completed
Push — master ( d5d69d...0875dd )
by Igor
13s
created

Statement::info()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 11
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 9.9666
cc 1
nc 1
nop 0
crap 1
1
<?php
0 ignored issues
show
introduced by
Missing declare(strict_types=1).
Loading history...
2
3
namespace ClickHouseDB;
4
5
use ClickHouseDB\Exception\DatabaseException;
6
use ClickHouseDB\Exception\QueryException;
7
use ClickHouseDB\Query\Query;
8
use ClickHouseDB\Transport\CurlerRequest;
9
use ClickHouseDB\Transport\CurlerResponse;
10
11
class Statement
12
{
13
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$_rawData with single line content, use one-line comment instead.
Loading history...
14
     * @var string|mixed
15
     */
16
    private $_rawData;
17
18
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$_http_code with single line content, use one-line comment instead.
Loading history...
19
     * @var int
20
     */
21
    private $_http_code = -1;
0 ignored issues
show
introduced by
Class Statement contains unused property $_http_code.
Loading history...
22
23
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$_request with single line content, use one-line comment instead.
Loading history...
24
     * @var CurlerRequest
25
     */
26
    private $_request = null;
27
28
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$_init with single line content, use one-line comment instead.
Loading history...
29
     * @var bool
30
     */
31
    private $_init = false;
32
33
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$query with single line content, use one-line comment instead.
Loading history...
34
     * @var Query
35
     */
36
    private $query;
0 ignored issues
show
introduced by
Class Statement contains write-only property $query.
Loading history...
37
38
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$format with single line content, use one-line comment instead.
Loading history...
39
     * @var mixed
40
     */
41
    private $format;
42
43
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$sql with single line content, use one-line comment instead.
Loading history...
44
     * @var string
45
     */
46
    private $sql = '';
47
48
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$meta with single line content, use one-line comment instead.
Loading history...
49
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Statement::$meta does not specify type hint for its items.
Loading history...
50
     */
51
    private $meta;
52
53
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$totals with single line content, use one-line comment instead.
Loading history...
54
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Statement::$totals does not specify type hint for its items.
Loading history...
55
     */
56
    private $totals;
57
58
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$extremes with single line content, use one-line comment instead.
Loading history...
59
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Statement::$extremes does not specify type hint for its items.
Loading history...
60
     */
61
    private $extremes;
62
63
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$rows with single line content, use one-line comment instead.
Loading history...
64
     * @var int
65
     */
66
    private $rows;
67
68
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$rows_before_limit_at_least with single line content, use one-line comment instead.
Loading history...
69
     * @var bool|integer
0 ignored issues
show
introduced by
Expected "int" but found "integer" in @var annotation.
Loading history...
70
     */
71
    private $rows_before_limit_at_least = false;
72
73
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$array_data with single line content, use one-line comment instead.
Loading history...
74
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Statement::$array_data does not specify type hint for its items.
Loading history...
75
     */
76
    private $array_data = [];
77
78
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$statistics with single line content, use one-line comment instead.
Loading history...
79
     * @var array|null
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Statement::$statistics does not specify type hint for its items.
Loading history...
80
     */
81
    private $statistics = null;
82
83
84 40
    public function __construct(CurlerRequest $request)
85
    {
86 40
        $this->_request = $request;
87 40
        $this->format = $this->_request->getRequestExtendedInfo('format');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
88 40
        $this->query = $this->_request->getRequestExtendedInfo('query');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
89 40
        $this->sql = $this->_request->getRequestExtendedInfo('sql');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
90 40
    }
91
92
    /**
93
     * @return CurlerRequest
94
     */
95
    public function getRequest()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::getRequest() does not have return type hint for its return value but it should be possible to add it based on @return annotation "CurlerRequest".
Loading history...
96
    {
97
        return $this->_request;
98
    }
99
100
    /**
101
     * @return CurlerResponse
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
102
     * @throws Exception\TransportException
103
     */
104 36
    private function response()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::response() does not have return type hint for its return value but it should be possible to add it based on @return annotation "CurlerResponse".
Loading history...
105
    {
106 36
        return $this->_request->response();
107
    }
108
109
    /**
110
     * @return mixed
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
111
     * @throws Exception\TransportException
112
     */
113 1
    public function responseInfo()
114
    {
115 1
        return $this->response()->info();
116
    }
117
118
    /**
119
     * @return mixed|string
120
     */
121 9
    public function sql()
122
    {
123 9
        return $this->sql;
124
    }
125
126
    /**
127
     * @param string $body
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
128
     * @return array|bool
0 ignored issues
show
introduced by
@return annotation of method \ClickHouseDB\Statement::parseErrorClickHouse() does not specify type hint for items of its traversable return value.
Loading history...
129
     */
130 5
    private function parseErrorClickHouse($body)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::parseErrorClickHouse() does not have parameter type hint for its parameter $body but it should be possible to add it based on @param annotation "string".
Loading history...
131
    {
132 5
        $body = trim($body);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
introduced by
Function trim() should not be referenced via a fallback global name, but via a use statement.
Loading history...
133 5
        $mathes = [];
134
135
        // Code: 115, e.displayText() = DB::Exception: Unknown setting readonly[0], e.what() = DB::Exception
136
        // Code: 192, e.displayText() = DB::Exception: Unknown user x, e.what() = DB::Exception
137
        // Code: 60, e.displayText() = DB::Exception: Table default.ZZZZZ doesn't exist., e.what() = DB::Exception
138
139 5
        if (preg_match("%Code: (\d+),\se\.displayText\(\) \=\s*DB\:\:Exception\s*:\s*(.*)(?:\,\s*e\.what|\(version).*%ius", $body, $mathes)) {
0 ignored issues
show
introduced by
Function preg_match() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style Comprehensibility introduced by
The string literal %Code: (\d+),\se\.displa...\.what|\(version).*%ius does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
140 5
            return ['code' => $mathes[1], 'message' => $mathes[2]];
141
        }
142
143
        return false;
144
    }
145
146
    /**
147
     * @return bool
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
148
     * @throws Exception\TransportException
149
     */
150 8
    public function error()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::error() does not have return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
151
    {
152 8
        if (!$this->isError()) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
153 2
            return false;
154
        }
155
156 6
        $body = $this->response()->body();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
157 6
        $error_no = $this->response()->error_no();
158 6
        $error = $this->response()->error();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
159
160 6
        if (!$error_no && !$error) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
161 5
            $parse = $this->parseErrorClickHouse($body);
162
163 5
            if ($parse) {
0 ignored issues
show
introduced by
$parse is a non-empty array, thus is always true.
Loading history...
Bug Best Practice introduced by
The expression $parse of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
164 5
                throw new DatabaseException($parse['message'] . "\nIN:" . $this->sql(), $parse['code']);
165
            } else {
166
                $code = $this->response()->http_code();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
167
                $message = "HttpCode:" . $this->response()->http_code() . " ; " . $this->response()->error() . " ;" . $body;
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal HttpCode: does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal ; does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal ; does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
168
            }
169
        } else {
170 1
            $code = $error_no;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
171 1
            $message = $this->response()->error();
172
        }
173
174 1
        throw new QueryException($message, $code);
175
    }
176
177
    /**
178
     * @return bool
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
179
     * @throws Exception\TransportException
180
     */
181 36
    public function isError()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::isError() does not have return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
182
    {
183 36
        return ($this->response()->http_code() !== 200 || $this->response()->error_no());
0 ignored issues
show
introduced by
Usage of language construct "return" with parentheses is disallowed.
Loading history...
184
    }
185
186 29
    private function check() : bool
187
    {
188 29
        if (!$this->_request->isResponseExists()) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
189
            throw QueryException::noResponse();
190
        }
191
192 29
        if ($this->isError()) {
193 1
            $this->error();
194
        }
195
196 28
        return true;
197
    }
198
199
    /**
200
     * @return bool
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
201
     * @throws Exception\TransportException
202
     */
203 27
    private function init()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::init() does not have return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
204
    {
205 27
        if ($this->_init) {
206
            return false;
207
        }
208
209 27
        $this->check();
210
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
211
212 26
        $this->_rawData = $this->response()->rawDataOrJson($this->format);
213
214 26
        if (!$this->_rawData) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
215
            $this->_init = true;
216
            return false;
217
        }
218 26
        $data=[];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
219 26
        foreach (['meta', 'data', 'totals', 'extremes', 'rows', 'rows_before_limit_at_least', 'statistics'] as $key) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
220
221 26
            if (isset($this->_rawData[$key])) {
0 ignored issues
show
introduced by
Use early exit to reduce code nesting.
Loading history...
222 26
                if ($key=='data')
0 ignored issues
show
introduced by
Operator == is disallowed, use === instead.
Loading history...
223
                {
224 26
                    $data=$this->_rawData[$key];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
225
                }
226
                else{
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after ELSE keyword; 0 found
Loading history...
227 26
                    $this->{$key} = $this->_rawData[$key];
228
                }
229
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
230
            }
231
        }
232
233 26
        if (empty($this->meta)) {
234
            throw  new QueryException('Can`t find meta');
235
        }
236
237 26
        $isJSONCompact=(stripos($this->format,'JSONCompact')!==false?true:false);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 0 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
introduced by
Function stripos() should not be referenced via a fallback global name, but via a use statement.
Loading history...
238 26
        $this->array_data = [];
239 26
        foreach ($data as $rows) {
240 26
            $r = [];
241
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
242
243 26
            if ($isJSONCompact)
244
            {
245 1
                $r[]=$rows;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
246
            }
247
            else {
248 25
                foreach ($this->meta as $meta) {
249 25
                    $r[$meta['name']] = $rows[$meta['name']];
250
                }
251
            }
252
253 26
            $this->array_data[] = $r;
254
        }
255
256 26
        return true;
257
    }
258
259
    /**
260
     * @return array
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@return annotation of method \ClickHouseDB\Statement::extremes() does not specify type hint for items of its traversable return value.
Loading history...
261
     * @throws \Exception
0 ignored issues
show
introduced by
Class \Exception should not be referenced via a fully qualified name, but via a use statement.
Loading history...
262
     */
263
    public function extremes()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::extremes() does not have return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
264
    {
265
        $this->init();
266
        return $this->extremes;
267
    }
268
269
    /**
270
     * @return mixed
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
271
     * @throws Exception\TransportException
272
     */
273 1
    public function totalTimeRequest()
274
    {
275 1
        $this->check();
276 1
        return $this->response()->total_time();
277
278
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
279
280
    /**
281
     * @return array
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@return annotation of method \ClickHouseDB\Statement::extremesMin() does not specify type hint for items of its traversable return value.
Loading history...
282
     * @throws \Exception
0 ignored issues
show
introduced by
Class \Exception should not be referenced via a fully qualified name, but via a use statement.
Loading history...
283
     */
284 1
    public function extremesMin()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::extremesMin() does not have return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
285
    {
286 1
        $this->init();
287
288 1
        if (empty($this->extremes['min'])) {
289
            return [];
290
        }
291
292 1
        return $this->extremes['min'];
293
    }
294
295
    /**
296
     * @return array
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@return annotation of method \ClickHouseDB\Statement::extremesMax() does not specify type hint for items of its traversable return value.
Loading history...
297
     * @throws \Exception
0 ignored issues
show
introduced by
Class \Exception should not be referenced via a fully qualified name, but via a use statement.
Loading history...
298
     */
299
    public function extremesMax()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::extremesMax() does not have return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
300
    {
301
        $this->init();
302
303
        if (empty($this->extremes['max'])) {
304
            return [];
305
        }
306
307
        return $this->extremes['max'];
308
    }
309
310
    /**
311
     * @return array
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@return annotation of method \ClickHouseDB\Statement::totals() does not specify type hint for items of its traversable return value.
Loading history...
312
     * @throws Exception\TransportException
313
     */
314 1
    public function totals()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::totals() does not have return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
315
    {
316 1
        $this->init();
317 1
        return $this->totals;
318
    }
319
320
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
321
     *
322
     */
323
    public function dumpRaw()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::dumpRaw() does not have void return type hint.
Loading history...
introduced by
Method \ClickHouseDB\Statement::dumpRaw() does not need documentation comment.
Loading history...
324
    {
325
        print_r($this->_rawData);
0 ignored issues
show
introduced by
Function print_r() should not be referenced via a fallback global name, but via a use statement.
Loading history...
326
    }
327
328
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
329
     *
330
     */
331
    public function dump()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::dump() does not have void return type hint.
Loading history...
introduced by
Method \ClickHouseDB\Statement::dump() does not need documentation comment.
Loading history...
332
    {
333
        $this->_request->dump();
334
        $this->response()->dump();
335
    }
336
337
    /**
338
     * @return bool|int
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
339
     * @throws Exception\TransportException
340
     */
341 2
    public function countAll()
342
    {
343 2
        $this->init();
344 2
        return $this->rows_before_limit_at_least;
345
    }
346
347
    /**
348
     * @param bool $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
349
     * @return array|mixed|null
0 ignored issues
show
introduced by
@return annotation of method \ClickHouseDB\Statement::statistics() does not specify type hint for items of its traversable return value.
Loading history...
350
     * @throws Exception\TransportException
351
     */
352
    public function statistics($key = false)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::statistics() does not have parameter type hint for its parameter $key but it should be possible to add it based on @param annotation "bool".
Loading history...
353
    {
354
        $this->init();
355
        if ($key)
356
        {
357
            if (!is_array($this->statistics)) {
0 ignored issues
show
introduced by
Function is_array() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
358
                return null;
359
            }
360
            if (!isset($this->statistics[$key])) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
361
                return null;
362
            }
363
            return $this->statistics[$key];
364
        }
365
        return $this->statistics;
366
    }
367
368
    /**
369
     * @return int
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
370
     * @throws Exception\TransportException
371
     */
372 8
    public function count()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::count() does not have return type hint for its return value but it should be possible to add it based on @return annotation "int".
Loading history...
373
    {
374 8
        $this->init();
375 8
        return $this->rows;
376
    }
377
378
    /**
379
     * @return mixed|string
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
380
     * @throws Exception\TransportException
381
     */
382 3
    public function rawData()
383
    {
384 3
        if ($this->_init) {
385
            return $this->_rawData;
386
        }
387
388 3
        $this->check();
389
390 3
        return $this->response()->rawDataOrJson($this->format);
391
    }
392
393
    /**
394
     * @param string $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
395
     * @return mixed|null
396
     * @throws Exception\TransportException
397
     */
398 15
    public function fetchOne($key = '')
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::fetchOne() does not have parameter type hint for its parameter $key but it should be possible to add it based on @param annotation "string".
Loading history...
399
    {
400 15
        $this->init();
401
402 15
        if (isset($this->array_data[0])) {
403 15
            if ($key) {
404 15
                if (isset($this->array_data[0][$key])) {
405 14
                    return $this->array_data[0][$key];
406
                } else {
0 ignored issues
show
introduced by
Remove useless else to reduce code nesting.
Loading history...
407 1
                    return null;
408
                }
409
            }
410
411 2
            return $this->array_data[0];
412
        }
413
414
        return null;
415
    }
416
417
    /**
418
     * @param string|null $path
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
419
     * @return array
0 ignored issues
show
introduced by
@return annotation of method \ClickHouseDB\Statement::rowsAsTree() does not specify type hint for items of its traversable return value.
Loading history...
420
     * @throws Exception\TransportException
421
     */
422 4
    public function rowsAsTree($path)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::rowsAsTree() does not have parameter type hint for its parameter $path but it should be possible to add it based on @param annotation "string|null".
Loading history...
introduced by
Method \ClickHouseDB\Statement::rowsAsTree() does not have return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
423
    {
424 4
        $this->init();
425
426 4
        $out = [];
427 4
        foreach ($this->array_data as $row) {
428 4
            $d = $this->array_to_tree($row, $path);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
429 4
            $out = array_replace_recursive($d, $out);
0 ignored issues
show
introduced by
Function array_replace_recursive() should not be referenced via a fallback global name, but via a use statement.
Loading history...
430
        }
431
432 4
        return $out;
433
    }
434
435
    /**
436
     * Return size_upload,upload_content,speed_upload,time_request
437
     *
438
     * @return array
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@return annotation of method \ClickHouseDB\Statement::info_upload() does not specify type hint for items of its traversable return value.
Loading history...
439
     * @throws Exception\TransportException
440
     */
441
    public function info_upload()
0 ignored issues
show
Coding Style introduced by
Method name "Statement::info_upload" is not in camel caps format
Loading history...
introduced by
Method \ClickHouseDB\Statement::info_upload() does not have return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
442
    {
443
        $this->check();
444
        return [
445
            'size_upload'    => $this->response()->size_upload(),
446
            'upload_content' => $this->response()->upload_content_length(),
447
            'speed_upload'   => $this->response()->speed_upload(),
448
            'time_request'   => $this->response()->total_time()
0 ignored issues
show
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
449
        ];
450
    }
451
452
    /**
453
     * Return size_upload,upload_content,speed_upload,time_request,starttransfer_time,size_download,speed_download
454
     *
455
     * @return array
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@return annotation of method \ClickHouseDB\Statement::info() does not specify type hint for items of its traversable return value.
Loading history...
456
     * @throws Exception\TransportException
457
     */
458 1
    public function info()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::info() does not have return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
459
    {
460 1
        $this->check();
461
        return [
462 1
            'starttransfer_time'    => $this->response()->starttransfer_time(),
463 1
            'size_download'    => $this->response()->size_download(),
464 1
            'speed_download'    => $this->response()->speed_download(),
465 1
            'size_upload'    => $this->response()->size_upload(),
466 1
            'upload_content' => $this->response()->upload_content_length(),
467 1
            'speed_upload'   => $this->response()->speed_upload(),
468 1
            'time_request'   => $this->response()->total_time()
0 ignored issues
show
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
469
        ];
470
    }
471
472
    /**
473
     * get format in sql
474
     * @return mixed
0 ignored issues
show
introduced by
Expected 1 lines between description and annotations, found 0.
Loading history...
475
     */
476 1
    public function getFormat()
477
    {
478 1
        return $this->format;
479
    }
480
481
    /**
482
     * @return array
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@return annotation of method \ClickHouseDB\Statement::rows() does not specify type hint for items of its traversable return value.
Loading history...
483
     * @throws Exception\TransportException
484
     */
485 9
    public function rows()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::rows() does not have return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
486
    {
487 9
        $this->init();
488 8
        return $this->array_data;
489
    }
490
491
    /**
492
     * @param array|string $arr
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@param annotation of method \ClickHouseDB\Statement::array_to_tree() does not specify type hint for items of its traversable parameter $arr.
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
493
     * @param null|string|array $path
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
introduced by
@param annotation of method \ClickHouseDB\Statement::array_to_tree() does not specify type hint for items of its traversable parameter $path.
Loading history...
494
     * @return array
0 ignored issues
show
introduced by
@return annotation of method \ClickHouseDB\Statement::array_to_tree() does not specify type hint for items of its traversable return value.
Loading history...
495
     */
496 4
    private function array_to_tree($arr, $path = null)
0 ignored issues
show
Coding Style introduced by
Method name "Statement::array_to_tree" is not in camel caps format
Loading history...
introduced by
Method \ClickHouseDB\Statement::array_to_tree() does not have return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
497
    {
498 4
        if (is_array($path)) {
0 ignored issues
show
introduced by
Function is_array() should not be referenced via a fallback global name, but via a use statement.
Loading history...
499
            $keys = $path;
500
        } else {
501 4
            $args = func_get_args();
0 ignored issues
show
introduced by
Function func_get_args() should not be referenced via a fallback global name, but via a use statement.
Loading history...
502 4
            array_shift($args);
0 ignored issues
show
introduced by
Function array_shift() should not be referenced via a fallback global name, but via a use statement.
Loading history...
503
504 4
            if (sizeof($args) < 2) {
0 ignored issues
show
introduced by
Function sizeof() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
The use of function sizeof() is forbidden; use count() instead
Loading history...
505 4
                $separator = '.';
506 4
                $keys = explode($separator, $path);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
introduced by
Function explode() should not be referenced via a fallback global name, but via a use statement.
Loading history...
507
            } else {
508
                $keys = $args;
509
            }
510
        }
511
512
        //
0 ignored issues
show
introduced by
Empty comment
Loading history...
513 4
        $tree = $arr;
514 4
        while (count($keys)) {
0 ignored issues
show
introduced by
Function count() should not be referenced via a fallback global name, but via a use statement.
Loading history...
515 4
            $key = array_pop($keys);
0 ignored issues
show
introduced by
Function array_pop() should not be referenced via a fallback global name, but via a use statement.
Loading history...
516
517 4
            if (isset($arr[$key])) {
518 4
                $val = $arr[$key];
519
            } else {
520
                $val = $key;
521
            }
522
523 4
            $tree = array($val => $tree);
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
524
        }
525 4
        if (!is_array($tree)) {
0 ignored issues
show
introduced by
Function is_array() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
526
            return [];
527
        }
528 4
        return $tree;
529
    }
530
}
531