Passed
Push — master ( 4fd6c4...8c2820 )
by Igor
03:32
created

Statement::resetIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Statement::$iterator with single line content, use one-line comment instead.
Loading history...
84
     * @var int
85
     */
86
    public $iterator=0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
87
88
89 43
    public function __construct(CurlerRequest $request)
90
    {
91 43
        $this->_request = $request;
92 43
        $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...
93 43
        $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...
94 43
        $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...
95 43
    }
96
97
    /**
98
     * @return CurlerRequest
99
     */
100
    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...
101
    {
102
        return $this->_request;
103
    }
104
105
    /**
106
     * @return CurlerResponse
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
107
     * @throws Exception\TransportException
108
     */
109 37
    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...
110
    {
111 37
        return $this->_request->response();
112
    }
113
114
    /**
115
     * @return mixed
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
116
     * @throws Exception\TransportException
117
     */
118 1
    public function responseInfo()
119
    {
120 1
        return $this->response()->info();
121
    }
122
123
    /**
124
     * @return mixed|string
125
     */
126 11
    public function sql()
127
    {
128 11
        return $this->sql;
129
    }
130
131
    /**
132
     * @param string $body
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
133
     * @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...
134
     */
135 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...
136
    {
137 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...
138 5
        $mathes = [];
139
140
        // Code: 115, e.displayText() = DB::Exception: Unknown setting readonly[0], e.what() = DB::Exception
141
        // Code: 192, e.displayText() = DB::Exception: Unknown user x, e.what() = DB::Exception
142
        // Code: 60, e.displayText() = DB::Exception: Table default.ZZZZZ doesn't exist., e.what() = DB::Exception
143
144 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...
145 5
            return ['code' => $mathes[1], 'message' => $mathes[2]];
146
        }
147
148
        return false;
149
    }
150
151
    /**
152
     * @return bool
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
153
     * @throws Exception\TransportException
154
     */
155 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...
156
    {
157 8
        if (!$this->isError()) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
158 2
            return false;
159
        }
160
161 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...
162 6
        $error_no = $this->response()->error_no();
163 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...
164
165 6
        if (!$error_no && !$error) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
166 5
            $parse = $this->parseErrorClickHouse($body);
167
168 5
            if ($parse) {
0 ignored issues
show
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...
introduced by
$parse is a non-empty array, thus is always true.
Loading history...
169 5
                throw new DatabaseException($parse['message'] . "\nIN:" . $this->sql(), $parse['code']);
170
            } else {
171
                $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...
172
                $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...
173
            }
174
        } else {
175 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...
176 1
            $message = $this->response()->error();
177
        }
178
179 1
        throw new QueryException($message, $code);
180
    }
181
182
    /**
183
     * @return bool
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
184
     * @throws Exception\TransportException
185
     */
186 37
    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...
187
    {
188 37
        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...
189
    }
190
191 30
    private function check() : bool
192
    {
193 30
        if (!$this->_request->isResponseExists()) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
194
            throw QueryException::noResponse();
195
        }
196
197 30
        if ($this->isError()) {
198 1
            $this->error();
199
        }
200
201 29
        return true;
202
    }
203
204
    /**
205
     * @return bool
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
206
     * @throws Exception\TransportException
207
     */
208 28
    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...
209
    {
210 28
        if ($this->_init) {
211
            return false;
212
        }
213
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
214
215 28
        $this->check();
216
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
217
218 27
        $this->_rawData = $this->response()->rawDataOrJson($this->format);
219
220 27
        if (!$this->_rawData) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
221
            $this->_init = true;
222
            return false;
223
        }
224 27
        $data=[];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
225 27
        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...
226
227 27
            if (isset($this->_rawData[$key])) {
0 ignored issues
show
introduced by
Use early exit to reduce code nesting.
Loading history...
228 27
                if ($key=='data')
0 ignored issues
show
introduced by
Operator == is disallowed, use === instead.
Loading history...
229
                {
230 27
                    $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...
231
                }
232
                else{
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after ELSE keyword; 0 found
Loading history...
233 27
                    $this->{$key} = $this->_rawData[$key];
234
                }
235
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
236
            }
237
        }
238
239 27
        if (empty($this->meta)) {
240
            throw  new QueryException('Can`t find meta');
241
        }
242
243 27
        $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...
244 27
        $this->array_data = [];
245 27
        foreach ($data as $rows) {
246 27
            $r = [];
247
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
248
249 27
            if ($isJSONCompact)
250
            {
251 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...
252
            }
253
            else {
254 26
                foreach ($this->meta as $meta) {
255 26
                    $r[$meta['name']] = $rows[$meta['name']];
256
                }
257
            }
258
259 27
            $this->array_data[] = $r;
260
        }
261
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
262
263 27
        return true;
264
    }
265
266
    /**
267
     * @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...
268
     * @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...
269
     */
270
    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...
271
    {
272
        $this->init();
273
        return $this->extremes;
274
    }
275
276
    /**
277
     * @return mixed
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
278
     * @throws Exception\TransportException
279
     */
280 1
    public function totalTimeRequest()
281
    {
282 1
        $this->check();
283 1
        return $this->response()->total_time();
284
285
    }
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...
286
287
    /**
288
     * @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...
289
     * @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...
290
     */
291 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...
292
    {
293 1
        $this->init();
294
295 1
        if (empty($this->extremes['min'])) {
296
            return [];
297
        }
298
299 1
        return $this->extremes['min'];
300
    }
301
302
    /**
303
     * @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...
304
     * @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...
305
     */
306
    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...
307
    {
308
        $this->init();
309
310
        if (empty($this->extremes['max'])) {
311
            return [];
312
        }
313
314
        return $this->extremes['max'];
315
    }
316
317
    /**
318
     * @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...
319
     * @throws Exception\TransportException
320
     */
321 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...
322
    {
323 1
        $this->init();
324 1
        return $this->totals;
325
    }
326
327
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
328
     *
329
     */
330
    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...
331
    {
332
        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...
333
    }
334
335
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
336
     *
337
     */
338
    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...
339
    {
340
        $this->_request->dump();
341
        $this->response()->dump();
342
    }
343
344
    /**
345
     * @return bool|int
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
346
     * @throws Exception\TransportException
347
     */
348 2
    public function countAll()
349
    {
350 2
        $this->init();
351 2
        return $this->rows_before_limit_at_least;
352
    }
353
354
    /**
355
     * @param bool $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
356
     * @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...
357
     * @throws Exception\TransportException
358
     */
359
    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...
360
    {
361
        $this->init();
362
        if ($key)
363
        {
364
            if (!is_array($this->statistics)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
introduced by
Function is_array() should not be referenced via a fallback global name, but via a use statement.
Loading history...
365
                return null;
366
            }
367
            if (!isset($this->statistics[$key])) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
368
                return null;
369
            }
370
            return $this->statistics[$key];
371
        }
372
        return $this->statistics;
373
    }
374
375
    /**
376
     * @return int
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
377
     * @throws Exception\TransportException
378
     */
379 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...
380
    {
381 8
        $this->init();
382 8
        return $this->rows;
383
    }
384
385
    /**
386
     * @return mixed|string
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
387
     * @throws Exception\TransportException
388
     */
389 3
    public function rawData()
390
    {
391 3
        if ($this->_init) {
392
            return $this->_rawData;
393
        }
394
395 3
        $this->check();
396
397 3
        return $this->response()->rawDataOrJson($this->format);
398
    }
399
400
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
401
     *
402
     */
403 1
    public function resetIterator()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::resetIterator() does not have void return type hint.
Loading history...
introduced by
Method \ClickHouseDB\Statement::resetIterator() does not need documentation comment.
Loading history...
404
    {
405 1
        $this->iterator=0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
406 1
    }
407
408 1
    public function fetchRow($key = null)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::fetchRow() does not have parameter type hint nor @param annotation for its parameter $key.
Loading history...
introduced by
Method \ClickHouseDB\Statement::fetchRow() does not have return type hint nor @return annotation for its return value.
Loading history...
409
    {
410 1
        $this->init();
411
412 1
        $position=$this->iterator;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
413 1
        if (isset($this->array_data[$position])) {
414 1
            $this->iterator++;
415 1
            if ($key) {
416 1
                if (isset($this->array_data[$position][$key])) {
417 1
                    return $this->array_data[$position][$key];
418
                } else {
0 ignored issues
show
introduced by
Remove useless else to reduce code nesting.
Loading history...
419
                    return null;
420
                }
421
            }
422
            return $this->array_data[$position];
423
        }
424
425
        return null;
426
    }
427
    /**
428
     * @param string $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
429
     * @return mixed|null
430
     * @throws Exception\TransportException
431
     */
432 16
    public function fetchOne($key = null)
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...
433
    {
434 16
        $this->init();
435 16
        if (isset($this->array_data[0])) {
436 16
            if ($key) {
437 16
                if (isset($this->array_data[0][$key])) {
438 15
                    return $this->array_data[0][$key];
439
                } else {
0 ignored issues
show
introduced by
Remove useless else to reduce code nesting.
Loading history...
440 1
                    return null;
441
                }
442
            }
443 2
            return $this->array_data[0];
444
        }
445
        return null;
446
    }
447
448
    /**
449
     * @param string|null $path
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
450
     * @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...
451
     * @throws Exception\TransportException
452
     */
453 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...
454
    {
455 4
        $this->init();
456
457 4
        $out = [];
458 4
        foreach ($this->array_data as $row) {
459 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...
460 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...
461
        }
462
463 4
        return $out;
464
    }
465
466
    /**
467
     * Return size_upload,upload_content,speed_upload,time_request
468
     *
469
     * @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...
470
     * @throws Exception\TransportException
471
     */
472
    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...
473
    {
474
        $this->check();
475
        return [
476
            'size_upload'    => $this->response()->size_upload(),
477
            'upload_content' => $this->response()->upload_content_length(),
478
            'speed_upload'   => $this->response()->speed_upload(),
479
            '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...
480
        ];
481
    }
482
483
    /**
484
     * Return size_upload,upload_content,speed_upload,time_request,starttransfer_time,size_download,speed_download
485
     *
486
     * @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...
487
     * @throws Exception\TransportException
488
     */
489 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...
490
    {
491 1
        $this->check();
492
        return [
493 1
            'starttransfer_time'    => $this->response()->starttransfer_time(),
494 1
            'size_download'    => $this->response()->size_download(),
495 1
            'speed_download'    => $this->response()->speed_download(),
496 1
            'size_upload'    => $this->response()->size_upload(),
497 1
            'upload_content' => $this->response()->upload_content_length(),
498 1
            'speed_upload'   => $this->response()->speed_upload(),
499 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...
500
        ];
501
    }
502
503
    /**
504
     * get format in sql
505
     * @return mixed
0 ignored issues
show
introduced by
Expected 1 lines between description and annotations, found 0.
Loading history...
506
     */
507 1
    public function getFormat()
508
    {
509 1
        return $this->format;
510
    }
511
512
    /**
513
     * @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...
514
     * @throws Exception\TransportException
515
     */
516 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...
517
    {
518 9
        $this->init();
519 8
        return $this->array_data;
520
    }
521
522
    /**
523
     * @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...
524
     * @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...
525
     * @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...
526
     */
527 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...
528
    {
529 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...
530
            $keys = $path;
531
        } else {
532 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...
533 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...
534
535 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...
536 4
                $separator = '.';
537 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...
538
            } else {
539
                $keys = $args;
540
            }
541
        }
542
543
        //
0 ignored issues
show
introduced by
Empty comment
Loading history...
544 4
        $tree = $arr;
545 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...
546 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...
547
548 4
            if (isset($arr[$key])) {
549 4
                $val = $arr[$key];
550
            } else {
551
                $val = $key;
552
            }
553
554 4
            $tree = array($val => $tree);
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
555
        }
556 4
        if (!is_array($tree)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
introduced by
Function is_array() should not be referenced via a fallback global name, but via a use statement.
Loading history...
557
            return [];
558
        }
559 4
        return $tree;
560
    }
561
}
562