Passed
Pull Request — master (#76)
by
unknown
02:16
created

Http::prepareWrite()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

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