Passed
Push — master ( 1606b5...4950b0 )
by Igor
02:22
created

Http::streaming()   C

Complexity

Conditions 9
Paths 322

Size

Total Lines 62
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 10.7781

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 62
ccs 18
cts 25
cp 0.72
rs 5.6971
c 0
b 0
f 0
cc 9
nc 322
nop 2
crap 10.7781

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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