Completed
Push — master ( 990354...be1866 )
by Igor
25s queued 13s
created

Statement::countAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
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\ClickHouseUnavailableException;
6
use ClickHouseDB\Exception\DatabaseException;
7
use ClickHouseDB\Exception\QueryException;
8
use ClickHouseDB\Query\Query;
9
use ClickHouseDB\Transport\CurlerRequest;
10
use ClickHouseDB\Transport\CurlerResponse;
11
12
class Statement
13
{
14
    /**
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...
15
     * @var string|mixed
16
     */
17
    private $_rawData;
18
19
    /**
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...
20
     * @var int
21
     */
22
    private $_http_code = -1;
0 ignored issues
show
Coding Style introduced by
Member variable "_http_code" is not in valid camel caps format
Loading history...
23
24
    /**
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...
25
     * @var CurlerRequest
26
     */
27
    private $_request = null;
28
29
    /**
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...
30
     * @var bool
31
     */
32
    private $_init = false;
33
34
    /**
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...
35
     * @var Query
36
     */
37
    private $query;
38
39
    /**
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...
40
     * @var mixed
41
     */
42
    private $format;
43
44
    /**
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...
45
     * @var string
46
     */
47
    private $sql = '';
48
49
    /**
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...
50
     * @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...
51
     */
52
    private $meta;
53
54
    /**
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...
55
     * @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...
56
     */
57
    private $totals;
58
59
    /**
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...
60
     * @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...
61
     */
62
    private $extremes;
63
64
    /**
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...
65
     * @var int
66
     */
67
    private $rows;
68
69
    /**
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...
70
     * @var bool|integer
0 ignored issues
show
introduced by
Expected "int" but found "integer" in @var annotation.
Loading history...
71
     */
72
    private $rows_before_limit_at_least = false;
0 ignored issues
show
Coding Style introduced by
Member variable "rows_before_limit_at_least" is not in valid camel caps format
Loading history...
73
74
    /**
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...
75
     * @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...
76
     */
77
    private $array_data = [];
0 ignored issues
show
Coding Style introduced by
Member variable "array_data" is not in valid camel caps format
Loading history...
78
79
    /**
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...
80
     * @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...
81
     */
82
    private $statistics = null;
83
84
    /**
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...
85
     * @var int
86
     */
87
    public $iterator = 0;
88
89
90 45
    public function __construct(CurlerRequest $request)
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before function; 2 found
Loading history...
91
    {
92 45
        $this->_request = $request;
93 45
        $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...
94 45
        $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...
95 45
        $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...
96 45
    }
97
98
    /**
99
     * @return CurlerRequest
100
     */
101
    public function getRequest()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::getRequest() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "CurlerRequest".
Loading history...
102
    {
103
        return $this->_request;
104
    }
105
106
    /**
107
     * @return CurlerResponse
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
108
     * @throws Exception\TransportException
109
     */
110 39
    private function response()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::response() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "CurlerResponse".
Loading history...
111
    {
112 39
        return $this->_request->response();
113
    }
114
115
    /**
116
     * @return mixed
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
117
     * @throws Exception\TransportException
118
     */
119 1
    public function responseInfo()
120
    {
121 1
        return $this->response()->info();
122
    }
123
124
    /**
125
     * @return mixed|string
126
     */
127 10
    public function sql()
128
    {
129 10
        return $this->sql;
130
    }
131
132
    /**
133
     * @param string $body
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
134
     * @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...
135
     */
136 5
    private function parseErrorClickHouse($body)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::parseErrorClickHouse() does not have native type hint for its parameter $body but it should be possible to add it based on @param annotation "string".
Loading history...
137
    {
138 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...
139 5
        $mathes = [];
140
141
        // Code: 115, e.displayText() = DB::Exception: Unknown setting readonly[0], e.what() = DB::Exception
142
        // Code: 192, e.displayText() = DB::Exception: Unknown user x, e.what() = DB::Exception
143
        // Code: 60, e.displayText() = DB::Exception: Table default.ZZZZZ doesn't exist., e.what() = DB::Exception
144
145 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...
146 4
            return ['code' => $mathes[1], 'message' => $mathes[2]];
147
        }
148
149 1
        return false;
150
    }
151
152
    /**
153
     * @return bool
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
154
     * @throws Exception\TransportException
155
     */
156 8
    public function error()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::error() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
157
    {
158 8
        if (!$this->isError()) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
159 2
            return false;
160
        }
161
162 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...
163 6
        $error_no = $this->response()->error_no();
0 ignored issues
show
Coding Style introduced by
The variable $error_no should be in camel caps format.
Loading history...
164 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...
165
166 6
        $dumpStatement = false;
167 6
        if (!$error_no && !$error) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
Coding Style introduced by
The variable $error_no should be in camel caps format.
Loading history...
168 5
            $parse = $this->parseErrorClickHouse($body);
169
170 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...
171 4
                throw new DatabaseException($parse['message'] . "\nIN:" . $this->sql(), $parse['code']);
172
            } else {
0 ignored issues
show
introduced by
Remove useless "else" to reduce code nesting.
Loading history...
173 1
                $code = $this->response()->http_code();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 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...
174 1
                $message = "HttpCode:" . $this->response()->http_code() . " ; " . $this->response()->error() . " ;" . $body;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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...
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...
175 1
                $dumpStatement = true;
176
            }
177
        } else {
178 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...
Coding Style introduced by
The variable $error_no should be in camel caps format.
Loading history...
179 1
            $message = $this->response()->error();
180
        }
181
182 2
        $exception = new QueryException($message, $code);
183 2
        if ($code === CURLE_COULDNT_CONNECT) {
0 ignored issues
show
introduced by
Constant CURLE_COULDNT_CONNECT should not be referenced via a fallback global name, but via a use statement.
Loading history...
184
            $exception = new ClickHouseUnavailableException($message, $code);
185
        }
186
187 2
        if ($dumpStatement) {
0 ignored issues
show
introduced by
The condition $dumpStatement is always false.
Loading history...
188 1
            $exception->setRequestDetails($this->_request->getDetails());
189 1
            $exception->setResponseDetails($this->response()->getDetails());
190
        }
191
192 2
        throw $exception;
193
    }
194
195
    /**
196
     * @return bool
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
197
     * @throws Exception\TransportException
198
     */
199 39
    public function isError()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::isError() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
200
    {
201 39
        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...
202
    }
203
204 32
    private function check() : bool
0 ignored issues
show
introduced by
There must be no whitespace between closing parenthesis and return type colon.
Loading history...
205
    {
206 32
        if (!$this->_request->isResponseExists()) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
207
            throw QueryException::noResponse();
208
        }
209
210 32
        if ($this->isError()) {
211 1
            $this->error();
212
        }
213
214 31
        return true;
215
    }
216
217
    /**
218
     * @return bool
219
     */
220
    public function isInited()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::isInited() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
221 30
    {
222
        return $this->_init;
223 30
    }
224
225
    /**
226
     * @return bool
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
227
     * @throws Exception\TransportException
228 30
     */
229
    private function init()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::init() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
230
    {
231 29
        if ($this->_init) {
232
            return false;
233 29
        }
234
235
        $this->check();
236
237 29
        $this->_rawData = $this->response()->rawDataOrJson($this->format);
238 29
239
        if (!$this->_rawData) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
240 29
            $this->_init = true;
241 29
            return false;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
242
        }
243 29
244
        $data = [];
245
        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...
246 29
247
            if (isset($this->_rawData[$key])) {
0 ignored issues
show
introduced by
Use early exit to reduce code nesting.
Loading history...
248
                if ($key=='data') {
0 ignored issues
show
Coding Style introduced by
Expected at least 1 space before "=="; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "=="; 0 found
Loading history...
introduced by
Operator == is disallowed, use === instead.
Loading history...
249
                    $data=$this->_rawData[$key];
0 ignored issues
show
Coding Style introduced by
Expected at least 1 space before "="; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "="; 0 found
Loading history...
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
250
                } else {
251
                    $this->{$key} = $this->_rawData[$key];
252 29
                }
253
            }
254
        }
255
256 29
        if (empty($this->meta)) {
257 29
            throw new QueryException('Can`t find meta');
258 29
        }
259 29
260
        $isJSONCompact=(stripos($this->format,'JSONCompact')!==false?true:false);
0 ignored issues
show
Coding Style introduced by
Expected at least 1 space after ":"; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space before ":"; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space before "="; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "="; 0 found
Loading history...
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...
Coding Style introduced by
Expected at least 1 space before "!=="; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "!=="; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space before "?"; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "?"; 0 found
Loading history...
introduced by
Useless ternary operator.
Loading history...
introduced by
Function stripos() should not be referenced via a fallback global name, but via a use statement.
Loading history...
261
        $this->array_data = [];
0 ignored issues
show
Coding Style introduced by
Member variable "array_data" is not in valid camel caps format
Loading history...
262 29
        foreach ($data as $rows) {
263
            $r = [];
264 1
265
            if ($isJSONCompact) {
266
                $r[] = $rows;
267 28
            } else {
268 28
                foreach ($this->meta as $meta) {
269
                    $r[$meta['name']] = $rows[$meta['name']];
270
                }
271
            }
272 29
273
            $this->array_data[] = $r;
0 ignored issues
show
Coding Style introduced by
Member variable "array_data" is not in valid camel caps format
Loading history...
274
        }
275
276 29
        $this->_init = true;
277
278
        return true;
279
    }
280
281
    /**
282
     * @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...
283
     * @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...
284
     */
285
    public function extremes()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::extremes() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
286
    {
287
        $this->init();
288
        return $this->extremes;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
289
    }
290
291
    /**
292
     * @return mixed
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
293 1
     * @throws Exception\TransportException
294
     */
295 1
    public function totalTimeRequest()
296 1
    {
297
        $this->check();
298
        return $this->response()->total_time();
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
introduced by
Expected 0 lines after "return", found 1.
Loading history...
299
300
    }
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...
301
302
    /**
303
     * @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...
304 1
     * @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 1
    public function extremesMin()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::extremesMin() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
307
    {
308 1
        $this->init();
309
310
        if (empty($this->extremes['min'])) {
311
            return [];
312 1
        }
313
314
        return $this->extremes['min'];
315
    }
316
317
    /**
318
     * @return array
0 ignored issues
show
introduced by
@return annotation of method \ClickHouseDB\Statement::extremesMax() does not specify type hint for items of its traversable return value.
Loading history...
introduced by
Incorrect annotations group.
Loading history...
319
     * @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...
320
     */
321
    public function extremesMax()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::extremesMax() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
322
    {
323
        $this->init();
324
325
        if (empty($this->extremes['max'])) {
326
            return [];
327
        }
328
329
        return $this->extremes['max'];
330
    }
331
332
    /**
333
     * @return array
0 ignored issues
show
introduced by
@return annotation of method \ClickHouseDB\Statement::totals() does not specify type hint for items of its traversable return value.
Loading history...
introduced by
Incorrect annotations group.
Loading history...
334 1
     * @throws Exception\TransportException
335
     */
336 1
    public function totals()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::totals() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
337 1
    {
338
        $this->init();
339
        return $this->totals;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
340
    }
341
342
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
343
     *
344
     */
345
    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...
346
    {
347
        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...
348
    }
349
350
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
351
     *
352
     */
353
    public function dump()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::dump() does not need documentation comment.
Loading history...
introduced by
Method \ClickHouseDB\Statement::dump() does not have void return type hint.
Loading history...
354
    {
355
        $this->_request->dump();
356
        $this->response()->dump();
357
    }
358
359
    /**
360
     * @return bool|int
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
361 2
     * @throws Exception\TransportException
362
     */
363 2
    public function countAll()
364 2
    {
365
        $this->init();
366
        return $this->rows_before_limit_at_least;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
Coding Style introduced by
Member variable "rows_before_limit_at_least" is not in valid camel caps format
Loading history...
367
    }
368
369
    /**
370
     * @param bool $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
371
     * @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...
372
     * @throws Exception\TransportException
373
     */
374
    public function statistics($key = false)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::statistics() does not have native type hint for its parameter $key but it should be possible to add it based on @param annotation "bool".
Loading history...
375
    {
376
        $this->init();
377
378
        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...
379
            return null;
380
        }
381
382
        if (!$key) return $this->statistics;
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
introduced by
Expected 1 lines before "return", found -1.
Loading history...
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
383
384
        if (!isset($this->statistics[$key])) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
385
            return null;
386
        }
387
388
        return $this->statistics[$key];
0 ignored issues
show
introduced by
Expected 0 lines after "return", found 1.
Loading history...
389
390
    }
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...
391
392
    /**
393
     * @return int
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
394 8
     * @throws Exception\TransportException
395
     */
396 8
    public function count()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::count() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "int".
Loading history...
397 8
    {
398
        $this->init();
399
        return $this->rows;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
400
    }
401
402
    /**
403
     * @return mixed|string
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
404 3
     * @throws Exception\TransportException
405
     */
406 3
    public function rawData()
407
    {
408
        if ($this->_init) {
409
            return $this->_rawData;
410 3
        }
411
412 3
        $this->check();
413
414
        return $this->response()->rawDataOrJson($this->format);
415
    }
416
417
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
418 2
     *
419
     */
420 2
    public function resetIterator()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::resetIterator() does not need documentation comment.
Loading history...
introduced by
Method \ClickHouseDB\Statement::resetIterator() does not have void return type hint.
Loading history...
421 2
    {
422
        $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...
Coding Style introduced by
Expected at least 1 space after "="; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space before "="; 0 found
Loading history...
423 2
    }
424
425 2
    public function fetchRow($key = null)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::fetchRow() does not have return type hint nor @return annotation for its return value.
Loading history...
introduced by
Method \ClickHouseDB\Statement::fetchRow() does not have parameter type hint nor @param annotation for its parameter $key.
Loading history...
426
    {
427 2
        $this->init();
428
429 2
        $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...
Coding Style introduced by
Expected at least 1 space after "="; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space before "="; 0 found
Loading history...
430
431
        if (!isset($this->array_data[$position])) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
Coding Style introduced by
Member variable "array_data" is not in valid camel caps format
Loading history...
432
            return null;
433 2
        }
434
435 2
        $this->iterator++;
436
437
        if (!$key) {
0 ignored issues
show
introduced by
Expected 1 lines after "if", found 0.
Loading history...
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
438 2
            return $this->array_data[$position];
0 ignored issues
show
Coding Style introduced by
Member variable "array_data" is not in valid camel caps format
Loading history...
439 1
        }
440
        if (!isset($this->array_data[$position][$key])) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
Coding Style introduced by
Member variable "array_data" is not in valid camel caps format
Loading history...
441
            return null;
442 2
        }
443
444
        return $this->array_data[$position][$key];
0 ignored issues
show
Coding Style introduced by
Member variable "array_data" is not in valid camel caps format
Loading history...
introduced by
Expected 0 lines after "return", found 1.
Loading history...
445
446
    }
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...
Coding Style introduced by
Expected 1 blank line after function; 0 found
Loading history...
447
    /**
448
     * @param string $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
449
     * @return mixed|null
450 18
     * @throws Exception\TransportException
451
     */
452 18
    public function fetchOne($key = null)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::fetchOne() does not have native type hint for its parameter $key but it should be possible to add it based on @param annotation "string".
Loading history...
453 18
    {
454
        $this->init();
455
        if (!isset($this->array_data[0])) {
0 ignored issues
show
Coding Style introduced by
Member variable "array_data" is not in valid camel caps format
Loading history...
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
456
            return null;
457 18
        }
458 3
459
        if (!$key) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
460
            return $this->array_data[0];
0 ignored issues
show
Coding Style introduced by
Member variable "array_data" is not in valid camel caps format
Loading history...
461 18
        }
462 2
463
        if (!isset($this->array_data[0][$key])) {
0 ignored issues
show
Coding Style introduced by
Member variable "array_data" is not in valid camel caps format
Loading history...
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
464
            return null;
465 17
        }
466
467
        return $this->array_data[0][$key];
0 ignored issues
show
Coding Style introduced by
Member variable "array_data" is not in valid camel caps format
Loading history...
468
    }
469
470
    /**
471
     * @param string|null $path
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
472
     * @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...
473 4
     * @throws Exception\TransportException
474
     */
475 4
    public function rowsAsTree($path)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::rowsAsTree() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
introduced by
Method \ClickHouseDB\Statement::rowsAsTree() does not have native type hint for its parameter $path but it should be possible to add it based on @param annotation "string|null".
Loading history...
476
    {
477 4
        $this->init();
478 4
479 4
        $out = [];
480 4
        foreach ($this->array_data as $row) {
0 ignored issues
show
Coding Style introduced by
Member variable "array_data" is not in valid camel caps format
Loading history...
481
            $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...
482
            $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...
483 4
        }
484
485
        return $out;
486
    }
487
488
    /**
489
     * Return size_upload,upload_content,speed_upload,time_request
490
     *
491
     * @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...
492
     * @throws Exception\TransportException
493
     */
494
    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 native return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
495
    {
496
        $this->check();
497
        return [
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
498
            'size_upload'    => $this->response()->size_upload(),
499
            'upload_content' => $this->response()->upload_content_length(),
500
            'speed_upload'   => $this->response()->speed_upload(),
501
            'time_request'   => $this->response()->total_time()
0 ignored issues
show
introduced by
Multi-line arrays must have a trailing comma after the last element.
Loading history...
502
        ];
503
    }
504
505
    /**
506
     * Return size_upload,upload_content,speed_upload,time_request,starttransfer_time,size_download,speed_download
507
     *
508
     * @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...
509 1
     * @throws Exception\TransportException
510
     */
511 1
    public function info()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::info() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
512
    {
513 1
        $this->check();
514 1
        return [
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
515 1
            'starttransfer_time'    => $this->response()->starttransfer_time(),
516 1
            'size_download'    => $this->response()->size_download(),
517 1
            'speed_download'    => $this->response()->speed_download(),
518 1
            'size_upload'    => $this->response()->size_upload(),
519 1
            'upload_content' => $this->response()->upload_content_length(),
520
            'speed_upload'   => $this->response()->speed_upload(),
521
            'time_request'   => $this->response()->total_time()
0 ignored issues
show
introduced by
Multi-line arrays must have a trailing comma after the last element.
Loading history...
522
        ];
523
    }
524
525
    /**
526
     * get format in sql
527 1
     * @return mixed
0 ignored issues
show
introduced by
Expected 1 lines between description and annotations, found 0.
Loading history...
528
     */
529 1
    public function getFormat()
530
    {
531
        return $this->format;
532
    }
533
534
    /**
535
     * @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...
536 9
     * @throws Exception\TransportException
537
     */
538 9
    public function rows()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Statement::rows() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
539 8
    {
540
        $this->init();
541
        return $this->array_data;
0 ignored issues
show
Coding Style introduced by
Member variable "array_data" is not in valid camel caps format
Loading history...
introduced by
Expected 1 lines before "return", found 0.
Loading history...
542
    }
543
544
    /**
545
     * @param array|string $arr
0 ignored issues
show
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...
introduced by
Incorrect annotations group.
Loading history...
546
     * @param null|string|array $path
0 ignored issues
show
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...
introduced by
Null type hint should be on last position in "null|string|array".
Loading history...
547 4
     * @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...
548
     */
549 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 native return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
550
    {
551
        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...
552 4
            $keys = $path;
553 4
        } else {
554
            $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...
555 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...
556 4
557 4
            if (sizeof($args) < 2) {
0 ignored issues
show
Coding Style introduced by
The use of function sizeof() is forbidden; use count() instead
Loading history...
introduced by
Function sizeof() should not be referenced via a fallback global name, but via a use statement.
Loading history...
558
                $separator = '.';
559
                $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...
560
            } else {
561
                $keys = $args;
562
            }
563
        }
564 4
565 4
        //
0 ignored issues
show
introduced by
Empty comment
Loading history...
566 4
        $tree = $arr;
567
        while (count($keys)) {
0 ignored issues
show
introduced by
Expected 1 lines after "while", found 0.
Loading history...
introduced by
Function count() should not be referenced via a fallback global name, but via a use statement.
Loading history...
568 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...
569 4
570
            if (isset($arr[$key])) {
571
                $val = $arr[$key];
572
            } else {
573
                $val = $key;
574 4
            }
575
576 4
            $tree = array($val => $tree);
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
577
        }
578
        if (!is_array($tree)) {
0 ignored issues
show
introduced by
Expected 1 lines after "if", found 0.
Loading history...
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...
579 4
            return [];
580
        }
581
        return $tree;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
582
    }
583
}
584