Passed
Pull Request — master (#140)
by Dmitriy
06:25
created

Http   F

Complexity

Total Complexity 82

Size/Duplication

Total Lines 709
Duplicated Lines 0 %

Test Coverage

Coverage 78.69%

Importance

Changes 42
Bugs 5 Features 8
Metric Value
eloc 224
c 42
b 5
f 8
dl 0
loc 709
ccs 192
cts 244
cp 0.7869
rs 2
wmc 82

34 Methods

Rating   Name   Duplication   Size   Complexity  
A makeRequest() 0 28 4
A getRequestWrite() 0 4 1
A getConnectTimeOut() 0 3 1
A writeAsyncCSV() 0 29 2
A verbose() 0 4 1
A addQueryDegeneration() 0 4 1
A executeAsync() 0 3 1
A streamRead() 0 5 1
A ping() 0 7 1
A getUri() 0 14 5
A getCurler() 0 3 1
A selectAsync() 0 5 1
A setConnectTimeOut() 0 3 1
A cleanQueryDegeneration() 0 4 1
A setDirtyCurler() 0 4 2
A setHost() 0 7 2
A __construct() 0 9 1
A writeStreamData() 0 22 2
A newRequest() 0 22 4
A prepareWrite() 0 8 2
C streaming() 0 56 9
A getUrl() 0 21 4
A settings() 0 3 1
A getCountPendingQueue() 0 3 1
A prepareQuery() 0 9 2
A select() 0 5 1
A streamWrite() 0 5 1
A prepareSelect() 0 8 2
A setCurler() 0 3 1
A write() 0 11 3
A setSslCa() 0 3 1
C getRequestRead() 0 58 12
B __findXClickHouseProgress() 0 31 8
A setProgressFunction() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like Http often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Http, and based on these observations, apply Extract Interface, too.

1
<?php
0 ignored issues
show
introduced by
An error occurred during processing; checking has been aborted. The error message was: "if" without curly braces is not supported.
Loading history...
introduced by
Missing declare(strict_types=1).
Loading history...
2
3
namespace ClickHouseDB\Transport;
4
5
use ClickHouseDB\Exception\TransportException;
6
use ClickHouseDB\Query\Degeneration;
7
use ClickHouseDB\Query\Query;
8
use ClickHouseDB\Query\WhereInFile;
9
use ClickHouseDB\Query\WriteToFile;
10
use ClickHouseDB\Settings;
11
use ClickHouseDB\Statement;
12
use const PHP_EOL;
13
14
class Http
15
{
16
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_username with single line content, use one-line comment instead.
Loading history...
17
     * @var string
18
     */
19
    private $_username = null;
20
21
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_password with single line content, use one-line comment instead.
Loading history...
22
     * @var string
23
     */
24
    private $_password = null;
25
26
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_host with single line content, use one-line comment instead.
Loading history...
27
     * @var string
28
     */
29
    private $_host = '';
30
31
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_port with single line content, use one-line comment instead.
Loading history...
32
     * @var int
33
     */
34
    private $_port = 0;
35
36
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_verbose with single line content, use one-line comment instead.
Loading history...
37
     * @var bool|int
38
     */
39
    private $_verbose = false;
40
41
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_curler with single line content, use one-line comment instead.
Loading history...
42
     * @var CurlerRolling
43
     */
44
    private $_curler = null;
45
46
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_settings with single line content, use one-line comment instead.
Loading history...
47
     * @var Settings
48
     */
49
    private $_settings = null;
50
51
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_query_degenerations with single line content, use one-line comment instead.
Loading history...
52
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Transport\Http::$_query_degenerations does not specify type hint for its items.
Loading history...
53
     */
54
    private $_query_degenerations = [];
55
56
    /**
57
     * Count seconds (int)
58
     *
59
     * @var int
60
     */
61
    private $_connectTimeOut = 5;
62
63
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$xClickHouseProgress with single line content, use one-line comment instead.
Loading history...
64
     * @var callable
65
     */
66
    private $xClickHouseProgress = null;
67
68
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$sslCA with single line content, use one-line comment instead.
Loading history...
69
     * @var null|string
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
70
     */
71
    private $sslCA = null;
72
73
    /**
74
     * Http constructor.
0 ignored issues
show
introduced by
Documentation comment contains forbidden comment "Http constructor.".
Loading history...
75
     * @param string $host
0 ignored issues
show
introduced by
Expected 1 lines between description and annotations, found 0.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
76
     * @param int $port
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
77
     * @param string $username
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
78
     * @param string $password
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
79
     */
80 66
    public function __construct($host, $port, $username, $password)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::__construct() does not have parameter type hint for its parameter $host but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::__construct() does not have parameter type hint for its parameter $port but it should be possible to add it based on @param annotation "int".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::__construct() does not have parameter type hint for its parameter $username but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::__construct() does not have parameter type hint for its parameter $password but it should be possible to add it based on @param annotation "string".
Loading history...
Coding Style introduced by
Type hint "string" missing for $host
Loading history...
Coding Style introduced by
Type hint "int" missing for $port
Loading history...
Coding Style introduced by
Type hint "string" missing for $username
Loading history...
Coding Style introduced by
Type hint "string" missing for $password
Loading history...
81
    {
82 66
        $this->setHost($host, $port);
83
84 66
        $this->_username = $username;
85 66
        $this->_password = $password;
86 66
        $this->_settings = new Settings($this);
87
88 66
        $this->setCurler();
89 66
    }
90
91
92 66
    public function setCurler()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::setCurler() does not have void return type hint.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function setCurler()
Loading history...
93
    {
94 66
        $this->_curler = new CurlerRolling();
95 66
    }
96
97
    /**
98
     * @param CurlerRolling $curler
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
99
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
100
    public function setDirtyCurler(CurlerRolling $curler)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::setDirtyCurler() does not have void return type hint.
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::setDirtyCurler() does not need documentation comment.
Loading history...
101
    {
102
        if ($curler instanceof CurlerRolling) {
0 ignored issues
show
introduced by
$curler is always a sub-type of ClickHouseDB\Transport\CurlerRolling.
Loading history...
introduced by
Use early exit to reduce code nesting.
Loading history...
103
            $this->_curler = $curler;
104
        }
105
    }
106
107
    /**
108
     * @return CurlerRolling
109
     */
110
    public function getCurler()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::getCurler() does not have return type hint for its return value but it should be possible to add it based on @return annotation "CurlerRolling".
Loading history...
111
    {
112
        return $this->_curler;
113
    }
114
115
    /**
116
     * @param string $host
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
117
     * @param int $port
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
118
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
119 66
    public function setHost($host, $port = -1)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::setHost() does not have parameter type hint for its parameter $host but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::setHost() does not have parameter type hint for its parameter $port but it should be possible to add it based on @param annotation "int".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::setHost() does not have void return type hint.
Loading history...
Coding Style introduced by
Type hint "string" missing for $host
Loading history...
Coding Style introduced by
Type hint "int" missing for $port
Loading history...
120
    {
121 66
        if ($port > 0) {
122 66
            $this->_port = $port;
123
        }
124
125 66
        $this->_host = $host;
126 66
    }
127
128
    /**
129
     * Sets client SSL certificate for Yandex Cloud
130
     *
131
     * @param string $caPath
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
132
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
133
    public function setSslCa($caPath)
0 ignored issues
show
Coding Style introduced by
Type hint "string" missing for $caPath
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::setSslCa() does not have parameter type hint for its parameter $caPath but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::setSslCa() does not have void return type hint.
Loading history...
134
    {
135
        $this->sslCA = $caPath;
136
    }
137
138
    /**
139
     * @return string
140
     */
141 53
    public function getUri()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::getUri() does not have return type hint for its return value but it should be possible to add it based on @return annotation "string".
Loading history...
142
    {
143 53
        $proto = 'http';
144 53
        if ($this->settings()->isHttps()) {
145 1
            $proto = 'https';
146
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
147 53
        $uri = $proto . '://' . $this->_host;
148 53
        if (stripos($this->_host, '/') !== false || stripos($this->_host, ':') !== false) {
0 ignored issues
show
introduced by
Function stripos() should not be referenced via a fallback global name, but via a use statement.
Loading history...
149 1
            return $uri;
150
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
151 53
        if (intval($this->_port) > 0) {
0 ignored issues
show
introduced by
Function intval() should not be referenced via a fallback global name, but via a use statement.
Loading history...
152 53
            return $uri . ':' . $this->_port;
153
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
154 1
        return $uri;
155
    }
156
157
    /**
158
     * @return Settings
159
     */
160 66
    public function settings()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::settings() does not have return type hint for its return value but it should be possible to add it based on @return annotation "Settings".
Loading history...
161
    {
162 66
        return $this->_settings;
163
    }
164
165
    /**
166
     * @param bool|int $flag
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "boolean|integer" but found "bool|int" for parameter type
Loading history...
167
     * @return mixed
168
     */
169
    public function verbose($flag)
170
    {
171
        $this->_verbose = $flag;
172
        return $flag;
173
    }
174
175
    /**
176
     * @param array $params
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@param annotation of method \ClickHouseDB\Transport\Http::getUrl() does not specify type hint for items of its traversable parameter $params.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
177
     * @return string
178
     */
179 43
    private function getUrl($params = [])
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::getUrl() does not have parameter type hint for its parameter $params but it should be possible to add it based on @param annotation "array".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::getUrl() does not have return type hint for its return value but it should be possible to add it based on @return annotation "string".
Loading history...
Coding Style introduced by
Type hint "array" missing for $params
Loading history...
180
    {
181 43
        $settings = $this->settings()->getSettings();
182
183 43
        if (is_array($params) && sizeof($params)) {
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...
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...
184 43
            $settings = array_merge($settings, $params);
0 ignored issues
show
introduced by
Function array_merge() should not be referenced via a fallback global name, but via a use statement.
Loading history...
185
        }
186
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
187
188 43
        if ($this->settings()->isReadOnlyUser()) {
189
            unset($settings['extremes']);
190
            unset($settings['readonly']);
191
            unset($settings['enable_http_compression']);
192
            unset($settings['max_execution_time']);
193
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
194
        }
195
196 43
        unset($settings['https']);
197
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
198
199 43
        return $this->getUri() . '?' . http_build_query($settings);
0 ignored issues
show
introduced by
Function http_build_query() should not be referenced via a fallback global name, but via a use statement.
Loading history...
200
    }
201
202
    /**
203
     * @param array $extendinfo
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@param annotation of method \ClickHouseDB\Transport\Http::newRequest() does not specify type hint for items of its traversable parameter $extendinfo.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
204
     * @return CurlerRequest
205
     */
206 43
    private function newRequest($extendinfo)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::newRequest() does not have parameter type hint for its parameter $extendinfo but it should be possible to add it based on @param annotation "array".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::newRequest() 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...
Coding Style introduced by
Type hint "array" missing for $extendinfo
Loading history...
207
    {
208 43
        $new = new CurlerRequest();
209 43
        $new->authByHeaders($this->_username, $this->_password)
210 43
            ->POST()
211 43
            ->setRequestExtendedInfo($extendinfo);
212
213 43
        if ($this->settings()->isEnableHttpCompression()) {
214 43
            $new->httpCompression(true);
215
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
216 43
        if ($this->settings()->getSessionId()) {
217 1
            $new->persistent();
218
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
219 43
        if ($this->sslCA) {
220
            $new->setSslCa($this->sslCA);
221
        }
222
223 43
        $new->timeOut($this->settings()->getTimeOut());
224 43
        $new->connectTimeOut($this->_connectTimeOut);//->keepAlive(); // one sec
225 43
        $new->verbose(boolval($this->_verbose));
0 ignored issues
show
introduced by
Function boolval() should not be referenced via a fallback global name, but via a use statement.
Loading history...
226
227 43
        return $new;
228
    }
229
230
    /**
231
     * @param Query $query
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::makeRequest() has useless @param annotation for parameter $query.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
232
     * @param array $urlParams
0 ignored issues
show
introduced by
@param annotation of method \ClickHouseDB\Transport\Http::makeRequest() does not specify type hint for items of its traversable parameter $urlParams.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
233
     * @param bool $query_as_string
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "boolean" but found "bool" for parameter type
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
234
     * @return CurlerRequest
235
     * @throws \ClickHouseDB\Exception\TransportException
0 ignored issues
show
introduced by
Class \ClickHouseDB\Exception\TransportException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
236
     */
237 43
    private function makeRequest(Query $query, $urlParams = [], $query_as_string = false)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::makeRequest() does not have parameter type hint for its parameter $urlParams but it should be possible to add it based on @param annotation "array".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::makeRequest() does not have parameter type hint for its parameter $query_as_string but it should be possible to add it based on @param annotation "bool".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::makeRequest() 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...
Coding Style introduced by
Type hint "array" missing for $urlParams
Loading history...
Coding Style introduced by
Type hint "bool" missing for $query_as_string
Loading history...
238
    {
239 43
        $sql = $query->toSql();
240
241 43
        if ($query_as_string) {
242 1
            $urlParams['query'] = $sql;
243
        }
244
245 43
        $url = $this->getUrl($urlParams);
246
247
        $extendinfo = [
248 43
            'sql' => $sql,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 4 space(s) but found 1
Loading history...
249 43
            'query' => $query,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
250 43
            'format' => $query->getFormat()
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
251
        ];
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 22 space(s), but found 8.
Loading history...
252
253 43
        $new = $this->newRequest($extendinfo);
254 43
        $new->url($url);
255
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
256
257 43
        if (!$query_as_string) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
258 43
            $new->parameters_json($sql);
259
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
260 43
        if ($this->settings()->isEnableHttpCompression()) {
261 43
            $new->httpCompression(true);
262
        }
263
264 43
        return $new;
265
    }
266
267
    /**
268
     * @param string|Query $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
269
     * @return CurlerRequest
270
     */
271 3
    public function writeStreamData($sql)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::writeStreamData() 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...
272
    {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
273
274 3
        if ($sql instanceof Query) {
275 1
            $query = $sql;
276
        } else {
277 2
            $query = new Query($sql);
278
        }
279
280 3
        $url = $this->getUrl([
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 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...
281 3
            'readonly' => 0,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 30 spaces, but found 12.
Loading history...
282 3
            'query' => $query->toSql()
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 30 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 4 space(s) but found 1
Loading history...
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
283
        ]);
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 29 space(s), but found 8.
Loading history...
284
        $extendinfo = [
285 3
            'sql' => $sql,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 4 space(s) but found 1
Loading history...
286 3
            'query' => $query,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
287 3
            'format' => $query->getFormat()
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
288
        ];
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 22 space(s), but found 8.
Loading history...
289
290 3
        $request = $this->newRequest($extendinfo);
291 3
        $request->url($url);
292 3
        return $request;
293
    }
294
295
296
    /**
297
     * @param string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
298
     * @param string $file_name
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
299
     * @return Statement
300
     * @throws \ClickHouseDB\Exception\TransportException
0 ignored issues
show
introduced by
Class \ClickHouseDB\Exception\TransportException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
301
     */
302 8
    public function writeAsyncCSV($sql, $file_name)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::writeAsyncCSV() does not have parameter type hint for its parameter $sql but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::writeAsyncCSV() does not have parameter type hint for its parameter $file_name but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::writeAsyncCSV() does not have return type hint for its return value but it should be possible to add it based on @return annotation "Statement".
Loading history...
Coding Style introduced by
Type hint "string" missing for $sql
Loading history...
Coding Style introduced by
Type hint "string" missing for $file_name
Loading history...
303
    {
304 8
        $query = new Query($sql);
305
306 8
        $url = $this->getUrl([
307 8
            'readonly' => 0,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 30 spaces, but found 12.
Loading history...
308 8
            'query' => $query->toSql()
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 30 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 4 space(s) but found 1
Loading history...
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
309
        ]);
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 29 space(s), but found 8.
Loading history...
310
311
        $extendinfo = [
312 8
            'sql' => $sql,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 4 space(s) but found 1
Loading history...
313 8
            'query' => $query,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
314 8
            'format' => $query->getFormat()
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
315
        ];
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 22 space(s), but found 8.
Loading history...
316
317 8
        $request = $this->newRequest($extendinfo);
318 8
        $request->url($url);
319
320
        $request->setCallbackFunction(function (CurlerRequest $request) {
0 ignored issues
show
introduced by
Closure not using "$this" should be declared static.
Loading history...
introduced by
Closure does not have void return type hint.
Loading history...
321 8
            $handle = $request->getInfileHandle();
322 8
            if (is_resource($handle)) {
0 ignored issues
show
introduced by
Use early exit to reduce code nesting.
Loading history...
introduced by
Function is_resource() should not be referenced via a fallback global name, but via a use statement.
Loading history...
323 8
                fclose($handle);
0 ignored issues
show
introduced by
Function fclose() should not be referenced via a fallback global name, but via a use statement.
Loading history...
324
            }
325 8
        });
326
327 8
        $request->setInfile($file_name);
328 8
        $this->_curler->addQueLoop($request);
329
330 8
        return new Statement($request);
331
    }
332
333
    /**
334
     * get Count Pending Query in Queue
335
     *
336
     * @return int
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for function return type
Loading history...
337
     */
338 12
    public function getCountPendingQueue()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::getCountPendingQueue() 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...
339
    {
340 12
        return $this->_curler->countPending();
341
    }
342
343
    /**
344
     * set Connect TimeOut in seconds [CURLOPT_CONNECTTIMEOUT] ( int )
345
     *
346
     * @param int $connectTimeOut
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
347
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
348 2
    public function setConnectTimeOut($connectTimeOut)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::setConnectTimeOut() does not have parameter type hint for its parameter $connectTimeOut but it should be possible to add it based on @param annotation "int".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::setConnectTimeOut() does not have void return type hint.
Loading history...
Coding Style introduced by
Type hint "int" missing for $connectTimeOut
Loading history...
349
    {
350 2
        $this->_connectTimeOut = $connectTimeOut;
351 2
    }
352
353
    /**
354
     * get ConnectTimeOut in seconds
355
     *
356
     * @return int
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for function return type
Loading history...
357
     */
358 37
    public function getConnectTimeOut()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::getConnectTimeOut() 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...
359
    {
360 37
        return $this->_connectTimeOut;
361
    }
362
363
364
    public function __findXClickHouseProgress($handle)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::__findXClickHouseProgress() does not have parameter type hint nor @param annotation for its parameter $handle.
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::__findXClickHouseProgress() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function __findXClickHouseProgress()
Loading history...
365
    {
366
        $code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
0 ignored issues
show
introduced by
Function curl_getinfo() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Constant CURLINFO_HTTP_CODE should not be referenced via a fallback global name, but via a use statement.
Loading history...
367
368
        // Search X-ClickHouse-Progress
369
        if ($code == 200) {
0 ignored issues
show
introduced by
Use early exit to reduce code nesting.
Loading history...
introduced by
Operator == is disallowed, use === instead.
Loading history...
370
            $response = curl_multi_getcontent($handle);
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...
introduced by
Function curl_multi_getcontent() should not be referenced via a fallback global name, but via a use statement.
Loading history...
371
            $header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
0 ignored issues
show
introduced by
Function curl_getinfo() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Constant CURLINFO_HEADER_SIZE should not be referenced via a fallback global name, but via a use statement.
Loading history...
372
            if (!$header_size) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
373
                return false;
374
            }
375
376
            $header = substr($response, 0, $header_size);
0 ignored issues
show
introduced by
Function substr() should not be referenced via a fallback global name, but via a use statement.
Loading history...
377
            if (!$header_size) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
378
                return false;
379
            }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
380
            $pos = strrpos($header, 'X-ClickHouse-Progress');
0 ignored issues
show
introduced by
Function strrpos() should not be referenced via a fallback global name, but via a use statement.
Loading history...
381
382
            if (!$pos) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
383
                return false;
384
            }
385
386
            $last = substr($header, $pos);
0 ignored issues
show
introduced by
Function substr() should not be referenced via a fallback global name, but via a use statement.
Loading history...
387
            $data = @json_decode(str_ireplace('X-ClickHouse-Progress:', '', $last), true);
0 ignored issues
show
introduced by
Function json_decode() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Function str_ireplace() should not be referenced via a fallback global name, but via a use statement.
Loading history...
388
389
            if ($data && is_callable($this->xClickHouseProgress)) {
0 ignored issues
show
introduced by
Function is_callable() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
390
391
                if (is_array($this->xClickHouseProgress)) {
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...
392
                    call_user_func_array($this->xClickHouseProgress, [$data]);
0 ignored issues
show
introduced by
Function call_user_func_array() should not be referenced via a fallback global name, but via a use statement.
Loading history...
393
                } else {
394
                    call_user_func($this->xClickHouseProgress, $data);
0 ignored issues
show
introduced by
Function call_user_func() should not be referenced via a fallback global name, but via a use statement.
Loading history...
395
                }
0 ignored issues
show
Coding Style introduced by
Blank line found after control structure
Loading history...
396
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
397
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
398
            }
0 ignored issues
show
Coding Style introduced by
Blank line found after control structure
Loading history...
399
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
400
        }
401
402
    }
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...
403
404
    /**
405
     * @param Query $query
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::getRequestRead() has useless @param annotation for parameter $query.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
406
     * @param null|WhereInFile $whereInFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
407
     * @param null|WriteToFile $writeToFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
408
     * @return CurlerRequest
409
     * @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...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
410
     */
411 38
    public function getRequestRead(Query $query, $whereInFile = null, $writeToFile = null)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::getRequestRead() does not have parameter type hint for its parameter $whereInFile but it should be possible to add it based on @param annotation "null|WhereInFile".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::getRequestRead() does not have parameter type hint for its parameter $writeToFile but it should be possible to add it based on @param annotation "null|WriteToFile".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::getRequestRead() 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...
412
    {
413 38
        $urlParams = ['readonly' => 2];
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...
414 38
        $query_as_string = false;
415
        // ---------------------------------------------------------------------------------
416 38
        if ($whereInFile instanceof WhereInFile && $whereInFile->size()) {
417
            // $request = $this->prepareSelectWhereIn($request, $whereInFile);
418 1
            $structure = $whereInFile->fetchUrlParams();
419
            // $structure = [];
420 1
            $urlParams = array_merge($urlParams, $structure);
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...
introduced by
Function array_merge() should not be referenced via a fallback global name, but via a use statement.
Loading history...
421 1
            $query_as_string = true;
422
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
423
        // ---------------------------------------------------------------------------------
424
        // if result to file
425 38
        if ($writeToFile instanceof WriteToFile && $writeToFile->fetchFormat()) {
426 1
            $query->setFormat($writeToFile->fetchFormat());
427 1
            unset($urlParams['extremes']);
428
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
429
        // ---------------------------------------------------------------------------------
430
        // makeRequest read
431 38
        $request = $this->makeRequest($query, $urlParams, $query_as_string);
432
        // ---------------------------------------------------------------------------------
433
        // attach files
434 38
        if ($whereInFile instanceof WhereInFile && $whereInFile->size()) {
435 1
            $request->attachFiles($whereInFile->fetchFiles());
436
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
437
        // ---------------------------------------------------------------------------------
438
        // result to file
439 38
        if ($writeToFile instanceof WriteToFile && $writeToFile->fetchFormat()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
440
441 1
            $fout = fopen($writeToFile->fetchFile(), 'w');
0 ignored issues
show
introduced by
Function fopen() should not be referenced via a fallback global name, but via a use statement.
Loading history...
442 1
            if (is_resource($fout)) {
0 ignored issues
show
introduced by
Function is_resource() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
443
444 1
                $isGz = $writeToFile->getGzip();
445
446 1
                if ($isGz) {
447
                    // write gzip header
448
                    // "\x1f\x8b\x08\x00\x00\x00\x00\x00"
449
                    // fwrite($fout, "\x1F\x8B\x08\x08".pack("V", time())."\0\xFF", 10);
450
                    // write the original file name
451
                    // $oname = str_replace("\0", "", basename($writeToFile->fetchFile()));
452
                    // fwrite($fout, $oname."\0", 1+strlen($oname));
453
454
                    fwrite($fout, "\x1f\x8b\x08\x00\x00\x00\x00\x00");
0 ignored issues
show
introduced by
Function fwrite() should not be referenced via a fallback global name, but via a use statement.
Loading history...
455
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
456
                }
457
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
458
459
                $request->setResultFileHandle($fout, $isGz)->setCallbackFunction(function (CurlerRequest $request) {
0 ignored issues
show
introduced by
Closure not using "$this" should be declared static.
Loading history...
introduced by
Closure does not have void return type hint.
Loading history...
460
                    fclose($request->getResultFileHandle());
0 ignored issues
show
introduced by
Function fclose() should not be referenced via a fallback global name, but via a use statement.
Loading history...
461 1
                });
462
            }
463
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
464 38
        if ($this->xClickHouseProgress) {
465
            $request->setFunctionProgress([$this, '__findXClickHouseProgress']);
466
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
467
        // ---------------------------------------------------------------------------------
468 38
        return $request;
469
470
    }
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...
471
472 1
    public function cleanQueryDegeneration()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::cleanQueryDegeneration() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function cleanQueryDegeneration()
Loading history...
473
    {
474 1
        $this->_query_degenerations = [];
475 1
        return true;
476
    }
477
478 66
    public function addQueryDegeneration(Degeneration $degeneration)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::addQueryDegeneration() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function addQueryDegeneration()
Loading history...
479
    {
480 66
        $this->_query_degenerations[] = $degeneration;
481 66
        return true;
482
    }
483
484
    /**
485
     * @param Query $query
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::getRequestWrite() has useless @param annotation for parameter $query.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
486
     * @return CurlerRequest
487
     * @throws \ClickHouseDB\Exception\TransportException
0 ignored issues
show
introduced by
Class \ClickHouseDB\Exception\TransportException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
488
     */
489 26
    public function getRequestWrite(Query $query)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::getRequestWrite() 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...
490
    {
491 26
        $urlParams = ['readonly' => 0];
492 26
        return $this->makeRequest($query, $urlParams);
493
    }
494
495
    /**
496
     * @throws TransportException
0 ignored issues
show
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
497
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
498 37
    public function ping(): bool
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
499
    {
500 37
        $request = new CurlerRequest();
501 37
        $request->url($this->getUri())->verbose(false)->GET()->connectTimeOut($this->getConnectTimeOut());
502 37
        $this->_curler->execOne($request);
503
504 37
        return $request->response()->body() === 'Ok.' . PHP_EOL;
505
    }
506
507
    /**
508
     * @param string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
509
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
510
     * @return Query
511
     */
512 44
    private function prepareQuery($sql, $bindings)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::prepareQuery() does not have parameter type hint for its parameter $sql but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::prepareQuery() does not have parameter type hint for its parameter $bindings but it should be possible to add it based on @param annotation "mixed[]".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::prepareQuery() does not have return type hint for its return value but it should be possible to add it based on @return annotation "Query".
Loading history...
Coding Style introduced by
Type hint "string" missing for $sql
Loading history...
Coding Style introduced by
Type hint "array" missing for $bindings
Loading history...
513
    {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
514
515
        // add Degeneration query
516 44
        foreach ($this->_query_degenerations as $degeneration) {
517 44
            $degeneration->bindParams($bindings);
518
        }
519
520 44
        return new Query($sql, $this->_query_degenerations);
521
    }
522
523
524
    /**
525
     * @param Query|string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
526
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
527
     * @param null|WhereInFile $whereInFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
528
     * @param null|WriteToFile $writeToFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
529
     * @return CurlerRequest
530
     * @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...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
531
     */
532 37
    private function prepareSelect($sql, $bindings, $whereInFile, $writeToFile = null)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::prepareSelect() 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...
Coding Style introduced by
Type hint "array" missing for $bindings
Loading history...
533
    {
534 37
        if ($sql instanceof Query) {
535
            return $this->getRequestWrite($sql);
536
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
537 37
        $query = $this->prepareQuery($sql, $bindings);
538 37
        $query->setFormat('JSON');
539 37
        return $this->getRequestRead($query, $whereInFile, $writeToFile);
540
    }
541
542
543
    /**
544
     * @param Query|string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
545
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
546
     * @return CurlerRequest
547
     * @throws \ClickHouseDB\Exception\TransportException
0 ignored issues
show
introduced by
Class \ClickHouseDB\Exception\TransportException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
548
     */
549 27
    private function prepareWrite($sql, $bindings = [])
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::prepareWrite() 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...
Coding Style introduced by
Type hint "array" missing for $bindings
Loading history...
550
    {
551 27
        if ($sql instanceof Query) {
552
            return $this->getRequestWrite($sql);
553
        }
554
555 27
        $query = $this->prepareQuery($sql, $bindings);
556 26
        return $this->getRequestWrite($query);
557
    }
558
559
    /**
560
     * @return bool
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
561
     * @throws \ClickHouseDB\Exception\TransportException
0 ignored issues
show
introduced by
Class \ClickHouseDB\Exception\TransportException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
562
     */
563 10
    public function executeAsync()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::executeAsync() 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...
564
    {
565 10
        return $this->_curler->execLoopWait();
566
    }
567
568
    /**
569
     * @param Query|string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
570
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
571
     * @param null|WhereInFile $whereInFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
572
     * @param null|WriteToFile $writeToFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
573
     * @return Statement
574
     * @throws \ClickHouseDB\Exception\TransportException
0 ignored issues
show
introduced by
Class \ClickHouseDB\Exception\TransportException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
575
     * @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...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
576
     */
577 30
    public function select($sql, array $bindings = [], $whereInFile = null, $writeToFile = null)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::select() does not have return type hint for its return value but it should be possible to add it based on @return annotation "Statement".
Loading history...
578
    {
579 30
        $request = $this->prepareSelect($sql, $bindings, $whereInFile, $writeToFile);
580 30
        $this->_curler->execOne($request);
581 30
        return new Statement($request);
582
    }
583
584
    /**
585
     * @param Query|string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
586
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
587
     * @param null|WhereInFile $whereInFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
588
     * @param null|WriteToFile $writeToFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
589
     * @return Statement
590
     * @throws \ClickHouseDB\Exception\TransportException
0 ignored issues
show
introduced by
Class \ClickHouseDB\Exception\TransportException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
591
     * @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...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
592
     */
593 7
    public function selectAsync($sql, array $bindings = [], $whereInFile = null, $writeToFile = null)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::selectAsync() does not have return type hint for its return value but it should be possible to add it based on @return annotation "Statement".
Loading history...
594
    {
595 7
        $request = $this->prepareSelect($sql, $bindings, $whereInFile, $writeToFile);
596 7
        $this->_curler->addQueLoop($request);
597 7
        return new Statement($request);
598
    }
599
600
    /**
601
     * @param callable $callback
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
602
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
603
    public function setProgressFunction(callable $callback)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::setProgressFunction() does not have void return type hint.
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::setProgressFunction() does not need documentation comment.
Loading history...
604
    {
605
        $this->xClickHouseProgress = $callback;
606
    }
607
608
    /**
609
     * @param string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
610
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
611
     * @param bool $exception
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "boolean" but found "bool" for parameter type
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
612
     * @return Statement
613
     * @throws \ClickHouseDB\Exception\TransportException
0 ignored issues
show
introduced by
Class \ClickHouseDB\Exception\TransportException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
614
     */
615 27
    public function write($sql, array $bindings = [], $exception = true)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::write() does not have parameter type hint for its parameter $sql but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::write() does not have parameter type hint for its parameter $exception but it should be possible to add it based on @param annotation "bool".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::write() does not have return type hint for its return value but it should be possible to add it based on @return annotation "Statement".
Loading history...
Coding Style introduced by
Type hint "string" missing for $sql
Loading history...
Coding Style introduced by
Type hint "bool" missing for $exception
Loading history...
616
    {
617 27
        $request = $this->prepareWrite($sql, $bindings);
618 26
        $this->_curler->execOne($request);
619 26
        $response = new Statement($request);
620 26
        if ($exception) {
621 26
            if ($response->isError()) {
622 3
                $response->error();
623
            }
624
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
625 24
        return $response;
626
    }
627
628
    /**
629
     * @param Stream $streamRW
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::streaming() has useless @param annotation for parameter $streamRW.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
630
     * @param CurlerRequest $request
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::streaming() has useless @param annotation for parameter $request.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
631
     * @return Statement
632
     * @throws \ClickHouseDB\Exception\TransportException
0 ignored issues
show
introduced by
Class \ClickHouseDB\Exception\TransportException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
633
     */
634 2
    private function streaming(Stream $streamRW, CurlerRequest $request)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::streaming() does not have return type hint for its return value but it should be possible to add it based on @return annotation "Statement".
Loading history...
635
    {
636 2
        $callable = $streamRW->getClosure();
637 2
        $stream = $streamRW->getStream();
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...
638
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
639
640
        try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
641
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
642
643 2
            if (!is_callable($callable)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
introduced by
Function is_callable() should not be referenced via a fallback global name, but via a use statement.
Loading history...
644
                if ($streamRW->isWrite()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
645
646
                    $callable = function ($ch, $fd, $length) use ($stream) {
0 ignored issues
show
introduced by
Closure not using "$this" should be declared static.
Loading history...
647
                        return ($line = fread($stream, $length)) ? $line : '';
0 ignored issues
show
introduced by
Useless parentheses.
Loading history...
introduced by
Function fread() should not be referenced via a fallback global name, but via a use statement.
Loading history...
648
                    };
649
                } else {
650
                    $callable = function ($ch, $fd) use ($stream) {
0 ignored issues
show
introduced by
Closure not using "$this" should be declared static.
Loading history...
651
                        return fwrite($stream, $fd);
0 ignored issues
show
introduced by
Function fwrite() should not be referenced via a fallback global name, but via a use statement.
Loading history...
652
                    };
653
                }
654
            }
655
656 2
            if ($streamRW->isGzipHeader()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
657
658 1
                if ($streamRW->isWrite()) {
659 1
                    $request->header('Content-Encoding', 'gzip');
660 1
                    $request->header('Content-Type', 'application/x-www-form-urlencoded');
661
                } else {
662
                    $request->header('Accept-Encoding', 'gzip');
663
                }
0 ignored issues
show
Coding Style introduced by
Blank line found after control structure
Loading history...
664
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
665
            }
666
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
667
668 2
            $request->header('Transfer-Encoding', 'chunked');
669
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
670
671 2
            if ($streamRW->isWrite()) {
672 1
                $request->setReadFunction($callable);
673
            } else {
674 1
                $request->setWriteFunction($callable);
675
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
676
677
//                $request->setHeaderFunction($callableHead);
678
            }
679
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
680
681 2
            $this->_curler->execOne($request, true);
682 2
            $response = new Statement($request);
683 2
            if ($response->isError()) {
684
                $response->error();
685
            }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
686 2
            return $response;
687
        } finally {
688 2
            if ($streamRW->isWrite())
0 ignored issues
show
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...
689 2
                fclose($stream);
0 ignored issues
show
introduced by
Function fclose() should not be referenced via a fallback global name, but via a use statement.
Loading history...
690
        }
691
692
693
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 2 blank lines before brace
Loading history...
694
695
696
    /**
697
     * @param Stream $streamRead
698
     * @param string $sql
699
     * @param mixed[] $bindings
700
     * @return Statement
701
     * @throws \ClickHouseDB\Exception\TransportException
0 ignored issues
show
introduced by
Class \ClickHouseDB\Exception\TransportException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
702
     */
703 1
    public function streamRead(Stream $streamRead, $sql, $bindings = [])
704
    {
705 1
        $sql = $this->prepareQuery($sql, $bindings);
706 1
        $request = $this->getRequestRead($sql);
707 1
        return $this->streaming($streamRead, $request);
708
709
    }
710
711
    /**
712
     * @param Stream $streamWrite
713
     * @param string $sql
714
     * @param mixed[] $bindings
715
     * @return Statement
716
     * @throws \ClickHouseDB\Exception\TransportException
0 ignored issues
show
introduced by
Class \ClickHouseDB\Exception\TransportException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
717
     */
718 1
    public function streamWrite(Stream $streamWrite, $sql, $bindings = [])
719
    {
720 1
        $sql = $this->prepareQuery($sql, $bindings);
721 1
        $request = $this->writeStreamData($sql);
722 1
        return $this->streaming($streamWrite, $request);
723
    }
724
}
725