Failed Conditions
Push — master ( e8febd...2f1601 )
by Igor
10:24
created

Http   F

Complexity

Total Complexity 85

Size/Duplication

Total Lines 766
Duplicated Lines 0 %

Test Coverage

Coverage 77.17%

Importance

Changes 44
Bugs 5 Features 8
Metric Value
eloc 243
c 44
b 5
f 8
dl 0
loc 766
ccs 196
cts 254
cp 0.7717
rs 2
wmc 85

34 Methods

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

How to fix   Complexity   

Complex Class

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

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

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

1
<?php
0 ignored issues
show
introduced by
An error occurred during processing; checking has been aborted. The error message was: "if" without curly braces is not supported.
Loading history...
introduced by
Missing declare(strict_types=1).
Loading history...
2
3
namespace ClickHouseDB\Transport;
4
5
use ClickHouseDB\Exception\TransportException;
6
use ClickHouseDB\Query\Degeneration;
7
use ClickHouseDB\Query\Query;
8
use ClickHouseDB\Query\WhereInFile;
9
use ClickHouseDB\Query\WriteToFile;
10
use ClickHouseDB\Settings;
11
use ClickHouseDB\Statement;
12
use const PHP_EOL;
13
14
class Http
15
{
16
    const AUTH_METHOD_HEADER       = 1;
0 ignored issues
show
introduced by
Constant \ClickHouseDB\Transport\Http::AUTH_METHOD_HEADER visibility missing.
Loading history...
17
    const AUTH_METHOD_QUERY_STRING = 2;
0 ignored issues
show
introduced by
Constant \ClickHouseDB\Transport\Http::AUTH_METHOD_QUERY_STRING visibility missing.
Loading history...
18
    const AUTH_METHOD_BASIC_AUTH   = 3;
0 ignored issues
show
introduced by
Constant \ClickHouseDB\Transport\Http::AUTH_METHOD_BASIC_AUTH visibility missing.
Loading history...
19
20
    const AUTH_METHODS_LIST = [
0 ignored issues
show
introduced by
Constant \ClickHouseDB\Transport\Http::AUTH_METHODS_LIST visibility missing.
Loading history...
21
        self::AUTH_METHOD_HEADER,
0 ignored issues
show
Coding Style introduced by
This array value does not seem to be aligned correcty; expected 31 spaces, but found 8.
Loading history...
22
        self::AUTH_METHOD_QUERY_STRING,
0 ignored issues
show
Coding Style introduced by
This array value does not seem to be aligned correcty; expected 31 spaces, but found 8.
Loading history...
23
        self::AUTH_METHOD_BASIC_AUTH,
0 ignored issues
show
Coding Style introduced by
This array value does not seem to be aligned correcty; expected 31 spaces, but found 8.
Loading history...
24
    ];
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 30 space(s), but found 4.
Loading history...
25
26
    /**
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...
27
     * @var string
28
     */
29
    private $_username = null;
30
31
    /**
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...
32
     * @var string
33
     */
34
    private $_password = null;
35
36
    /**
37
     * The username and password can be indicated in one of three ways:
38
     *  - Using HTTP Basic Authentication.
39
     *  - In the ‘user’ and ‘password’ URL parameters.
40
     *  - Using ‘X-ClickHouse-User’ and ‘X-ClickHouse-Key’ headers (by default)
41
     *
42
     * @see https://clickhouse.tech/docs/en/interfaces/http/
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
43
     * @var int
44
     */
45
    private $_authMethod = self::AUTH_METHOD_HEADER;
46
47
    /**
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...
48
     * @var string
49
     */
50
    private $_host = '';
51
52
    /**
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...
53
     * @var int
54
     */
55
    private $_port = 0;
56
57
    /**
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...
58
     * @var bool|int
59
     */
60
    private $_verbose = false;
61
62
    /**
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...
63
     * @var CurlerRolling
64
     */
65
    private $_curler = null;
66
67
    /**
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...
68
     * @var Settings
69
     */
70
    private $_settings = null;
71
72
    /**
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...
73
     * @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...
74
     */
75
    private $_query_degenerations = [];
76
77
    /**
78
     * Count seconds (int)
79
     *
80
     * @var int
81
     */
82
    private $_connectTimeOut = 5;
83
84
    /**
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...
85
     * @var callable
86
     */
87
    private $xClickHouseProgress = null;
88
89
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$sslCA with single line content, use one-line comment instead.
Loading history...
90
     * @var null|string
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
91
     */
92
    private $sslCA = null;
93
94
    /**
95
     * Http constructor.
0 ignored issues
show
introduced by
Documentation comment contains forbidden comment "Http constructor.".
Loading history...
96
     * @param string $host
0 ignored issues
show
introduced by
Expected 1 lines between description and annotations, found 0.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
97
     * @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...
98
     * @param string $username
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
99
     * @param string $password
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
100
     * @param int $authMethod
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
     */
102 66
    public function __construct($host, $port, $username, $password, $authMethod = null)
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...
introduced by
Method \ClickHouseDB\Transport\Http::__construct() does not have parameter type hint for its parameter $authMethod but it should be possible to add it based on @param annotation "int".
Loading history...
Coding Style introduced by
Type hint "int" missing for $authMethod
Loading history...
103
    {
104 66
        $this->setHost($host, $port);
105
106 66
        $this->_username = $username;
107 66
        $this->_password = $password;
108 66
        if ($authMethod) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $authMethod of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
109
            $this->_authMethod = $authMethod;
110
        }
111
112 66
        $this->_settings = new Settings($this);
113
114 66
        $this->setCurler();
115 66
    }
116
117
118 66
    public function setCurler()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::setCurler() does not have void return type hint.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function setCurler()
Loading history...
119
    {
120 66
        $this->_curler = new CurlerRolling();
121 66
    }
122
123
    /**
124
     * @param CurlerRolling $curler
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
125
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
126
    public function setDirtyCurler(CurlerRolling $curler)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::setDirtyCurler() does not have void return type hint.
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::setDirtyCurler() does not need documentation comment.
Loading history...
127
    {
128
        if ($curler instanceof CurlerRolling) {
0 ignored issues
show
introduced by
$curler is always a sub-type of ClickHouseDB\Transport\CurlerRolling.
Loading history...
introduced by
Use early exit to reduce code nesting.
Loading history...
129
            $this->_curler = $curler;
130
        }
131
    }
132
133
    /**
134
     * @return CurlerRolling
135
     */
136
    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...
137
    {
138
        return $this->_curler;
139
    }
140
141
    /**
142
     * @param string $host
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
143
     * @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...
144
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
145 66
    public function setHost($host, $port = -1)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::setHost() does not have parameter type hint for its parameter $host but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::setHost() does not have parameter type hint for its parameter $port but it should be possible to add it based on @param annotation "int".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::setHost() does not have void return type hint.
Loading history...
Coding Style introduced by
Type hint "string" missing for $host
Loading history...
Coding Style introduced by
Type hint "int" missing for $port
Loading history...
146
    {
147 66
        if ($port > 0) {
148 66
            $this->_port = $port;
149
        }
150
151 66
        $this->_host = $host;
152 66
    }
153
154
    /**
155
     * Sets client SSL certificate for Yandex Cloud
156
     *
157
     * @param string $caPath
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
158
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
159
    public function setSslCa($caPath)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::setSslCa() does not have parameter type hint for its parameter $caPath but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::setSslCa() does not have void return type hint.
Loading history...
Coding Style introduced by
Type hint "string" missing for $caPath
Loading history...
160
    {
161
        $this->sslCA = $caPath;
162
    }
163
164
    /**
165
     * @return string
166
     */
167 53
    public function getUri()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::getUri() does not have return type hint for its return value but it should be possible to add it based on @return annotation "string".
Loading history...
168
    {
169 53
        $proto = 'http';
170 53
        if ($this->settings()->isHttps()) {
171 1
            $proto = 'https';
172
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
173 53
        $uri = $proto . '://' . $this->_host;
174 53
        if (stripos($this->_host, '/') !== false || stripos($this->_host, ':') !== false) {
0 ignored issues
show
introduced by
Function stripos() should not be referenced via a fallback global name, but via a use statement.
Loading history...
175 1
            return $uri;
176
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
177 53
        if (intval($this->_port) > 0) {
0 ignored issues
show
introduced by
Function intval() should not be referenced via a fallback global name, but via a use statement.
Loading history...
178 53
            return $uri . ':' . $this->_port;
179
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
180 1
        return $uri;
181
    }
182
183
    /**
184
     * @return Settings
185
     */
186 66
    public function settings()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::settings() does not have return type hint for its return value but it should be possible to add it based on @return annotation "Settings".
Loading history...
187
    {
188 66
        return $this->_settings;
189
    }
190
191
    /**
192
     * @param bool|int $flag
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "boolean|integer" but found "bool|int" for parameter type
Loading history...
193
     * @return mixed
194
     */
195
    public function verbose($flag)
196
    {
197
        $this->_verbose = $flag;
198
        return $flag;
199
    }
200
201
    /**
202
     * @param array $params
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@param annotation of method \ClickHouseDB\Transport\Http::getUrl() does not specify type hint for items of its traversable parameter $params.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
203
     * @return string
204
     */
205 43
    private function getUrl($params = [])
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::getUrl() does not have parameter type hint for its parameter $params but it should be possible to add it based on @param annotation "array".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::getUrl() does not have return type hint for its return value but it should be possible to add it based on @return annotation "string".
Loading history...
Coding Style introduced by
Type hint "array" missing for $params
Loading history...
206
    {
207 43
        $settings = $this->settings()->getSettings();
208
209 43
        if (is_array($params) && sizeof($params)) {
0 ignored issues
show
introduced by
Function is_array() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Function sizeof() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
The use of function sizeof() is forbidden; use count() instead
Loading history...
210 43
            $settings = array_merge($settings, $params);
0 ignored issues
show
introduced by
Function array_merge() should not be referenced via a fallback global name, but via a use statement.
Loading history...
211
        }
212
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
213
214 43
        if ($this->settings()->isReadOnlyUser()) {
215
            unset($settings['extremes']);
216
            unset($settings['readonly']);
217
            unset($settings['enable_http_compression']);
218
            unset($settings['max_execution_time']);
219
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
220
        }
221
222 43
        unset($settings['https']);
223
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
224
225 43
        return $this->getUri() . '?' . http_build_query($settings);
0 ignored issues
show
introduced by
Function http_build_query() should not be referenced via a fallback global name, but via a use statement.
Loading history...
226
    }
227
228
    /**
229
     * @param array $extendinfo
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@param annotation of method \ClickHouseDB\Transport\Http::newRequest() does not specify type hint for items of its traversable parameter $extendinfo.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
230
     * @return CurlerRequest
231
     */
232 43
    private function newRequest($extendinfo)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::newRequest() does not have parameter type hint for its parameter $extendinfo but it should be possible to add it based on @param annotation "array".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::newRequest() does not have return type hint for its return value but it should be possible to add it based on @return annotation "CurlerRequest".
Loading history...
Coding Style introduced by
Type hint "array" missing for $extendinfo
Loading history...
233
    {
234 43
        $new = new CurlerRequest();
235
236 43
        switch ($this->_authMethod) {
237 43
            case self::AUTH_METHOD_QUERY_STRING:
238
                /* @todo: Move this implementation to CurlerRequest class. Possible options: the authentication method
239
                 *        should be applied in method `CurlerRequest:prepareRequest()`.
240
                 */
241
                $this->settings()->set('user', $this->_username);
242
                $this->settings()->set('password', $this->_password);
243
                break;
244 43
            case self::AUTH_METHOD_BASIC_AUTH:
245
                $new->authByBasicAuth($this->_username, $this->_password);
246
                break;
247
            default:
248
                // Auth with headers by default
249 43
                $new->authByHeaders($this->_username, $this->_password);
250 43
                break;
251
        }
252
253 43
        $new->POST()->setRequestExtendedInfo($extendinfo);
254
255 43
        if ($this->settings()->isEnableHttpCompression()) {
256 43
            $new->httpCompression(true);
257
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
258 43
        if ($this->settings()->getSessionId()) {
259 1
            $new->persistent();
260
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
261 43
        if ($this->sslCA) {
262
            $new->setSslCa($this->sslCA);
263
        }
264
265 43
        $new->timeOut($this->settings()->getTimeOut());
266 43
        $new->connectTimeOut($this->_connectTimeOut);//->keepAlive(); // one sec
267 43
        $new->verbose(boolval($this->_verbose));
0 ignored issues
show
introduced by
Function boolval() should not be referenced via a fallback global name, but via a use statement.
Loading history...
268
269 43
        return $new;
270
    }
271
272
    /**
273
     * @param Query $query
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::makeRequest() has useless @param annotation for parameter $query.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
274
     * @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...
275
     * @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...
276
     * @return CurlerRequest
277
     * @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...
278
     */
279 43
    private function makeRequest(Query $query, $urlParams = [], $query_as_string = false)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::makeRequest() does not have parameter type hint for its parameter $urlParams but it should be possible to add it based on @param annotation "array".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::makeRequest() does not have parameter type hint for its parameter $query_as_string but it should be possible to add it based on @param annotation "bool".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::makeRequest() does not have return type hint for its return value but it should be possible to add it based on @return annotation "CurlerRequest".
Loading history...
Coding Style introduced by
Type hint "array" missing for $urlParams
Loading history...
Coding Style introduced by
Type hint "bool" missing for $query_as_string
Loading history...
280
    {
281 43
        $sql = $query->toSql();
282
283 43
        if ($query_as_string) {
284 1
            $urlParams['query'] = $sql;
285
        }
286
287
        $extendinfo = [
288 43
            'sql' => $sql,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 4 space(s) but found 1
Loading history...
289 43
            'query' => $query,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
290 43
            'format' => $query->getFormat()
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
Coding Style introduced by
Each line in an array declaration must end in a comma
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 43
        $new = $this->newRequest($extendinfo);
294
295
        /*
296
         * Build URL after request making, since URL may contain auth data. This will not matter after the
297
         * implantation of the todo in the `HTTP:newRequest()` method.
298
         */
299 43
        $url = $this->getUrl($urlParams);
300 43
        $new->url($url);
301
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
302
303 43
        if (!$query_as_string) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
304 43
            $new->parameters_json($sql);
305
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
306 43
        if ($this->settings()->isEnableHttpCompression()) {
307 43
            $new->httpCompression(true);
308
        }
309
310 43
        return $new;
311
    }
312
313
    /**
314
     * @param string|Query $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
315
     * @return CurlerRequest
316
     */
317 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...
318
    {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
319
320 3
        if ($sql instanceof Query) {
321 1
            $query = $sql;
322
        } else {
323 2
            $query = new Query($sql);
324
        }
325
326
        $extendinfo = [
327 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...
328 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...
329 3
            'format' => $query->getFormat()
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
330
        ];
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...
331
332 3
        $request = $this->newRequest($extendinfo);
333
334
        /*
335
         * Build URL after request making, since URL may contain auth data. This will not matter after the
336
         * implantation of the todo in the `HTTP:newRequest()` method.
337
         */
338 3
        $url = $this->getUrl([
339 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...
340 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...
341
        ]);
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...
342
343 3
        $request->url($url);
344 3
        return $request;
345
    }
346
347
348
    /**
349
     * @param string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
350
     * @param string $file_name
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
351
     * @return Statement
352
     * @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...
353
     */
354 8
    public function writeAsyncCSV($sql, $file_name)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::writeAsyncCSV() does not have parameter type hint for its parameter $sql but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::writeAsyncCSV() does not have parameter type hint for its parameter $file_name but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::writeAsyncCSV() does not have return type hint for its return value but it should be possible to add it based on @return annotation "Statement".
Loading history...
Coding Style introduced by
Type hint "string" missing for $sql
Loading history...
Coding Style introduced by
Type hint "string" missing for $file_name
Loading history...
355
    {
356 8
        $query = new Query($sql);
357
358
        $extendinfo = [
359 8
            'sql' => $sql,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 4 space(s) but found 1
Loading history...
360 8
            'query' => $query,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
361 8
            'format' => $query->getFormat()
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
362
        ];
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...
363
364 8
        $request = $this->newRequest($extendinfo);
365
366
        /*
367
         * Build URL after request making, since URL may contain auth data. This will not matter after the
368
         * implantation of the todo in the `HTTP:newRequest()` method.
369
         */
370 8
        $url = $this->getUrl([
371 8
            'readonly' => 0,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 30 spaces, but found 12.
Loading history...
372 8
            'query' => $query->toSql()
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 30 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 4 space(s) but found 1
Loading history...
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
373
        ]);
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...
374
375 8
        $request->url($url);
376
377
        $request->setCallbackFunction(function (CurlerRequest $request) {
0 ignored issues
show
introduced by
Closure not using "$this" should be declared static.
Loading history...
introduced by
Closure does not have void return type hint.
Loading history...
378 8
            $handle = $request->getInfileHandle();
379 8
            if (is_resource($handle)) {
0 ignored issues
show
introduced by
Use early exit to reduce code nesting.
Loading history...
introduced by
Function is_resource() should not be referenced via a fallback global name, but via a use statement.
Loading history...
380 8
                fclose($handle);
0 ignored issues
show
introduced by
Function fclose() should not be referenced via a fallback global name, but via a use statement.
Loading history...
381
            }
382 8
        });
383
384 8
        $request->setInfile($file_name);
385 8
        $this->_curler->addQueLoop($request);
386
387 8
        return new Statement($request);
388
    }
389
390
    /**
391
     * get Count Pending Query in Queue
392
     *
393
     * @return int
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for function return type
Loading history...
394
     */
395 12
    public function getCountPendingQueue()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::getCountPendingQueue() does not have return type hint for its return value but it should be possible to add it based on @return annotation "int".
Loading history...
396
    {
397 12
        return $this->_curler->countPending();
398
    }
399
400
    /**
401
     * set Connect TimeOut in seconds [CURLOPT_CONNECTTIMEOUT] ( int )
402
     *
403
     * @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...
404
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
405 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...
406
    {
407 2
        $this->_connectTimeOut = $connectTimeOut;
408 2
    }
409
410
    /**
411
     * get ConnectTimeOut in seconds
412
     *
413
     * @return int
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for function return type
Loading history...
414
     */
415 37
    public function getConnectTimeOut()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::getConnectTimeOut() does not have return type hint for its return value but it should be possible to add it based on @return annotation "int".
Loading history...
416
    {
417 37
        return $this->_connectTimeOut;
418
    }
419
420
421
    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...
422
    {
423
        $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...
424
425
        // Search X-ClickHouse-Progress
426
        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...
427
            $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...
428
            $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...
429
            if (!$header_size) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
430
                return false;
431
            }
432
433
            $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...
434
            if (!$header_size) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
435
                return false;
436
            }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
437
            $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...
438
439
            if (!$pos) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
440
                return false;
441
            }
442
443
            $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...
444
            $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...
445
446
            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...
447
448
                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...
449
                    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...
450
                } else {
451
                    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...
452
                }
0 ignored issues
show
Coding Style introduced by
Blank line found after control structure
Loading history...
453
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
454
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
455
            }
0 ignored issues
show
Coding Style introduced by
Blank line found after control structure
Loading history...
456
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
457
        }
458
459
    }
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...
460
461
    /**
462
     * @param Query $query
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::getRequestRead() has useless @param annotation for parameter $query.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
463
     * @param null|WhereInFile $whereInFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
464
     * @param null|WriteToFile $writeToFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
465
     * @return CurlerRequest
466
     * @throws \Exception
0 ignored issues
show
introduced by
Class \Exception should not be referenced via a fully qualified name, but via a use statement.
Loading history...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
467
     */
468 38
    public function getRequestRead(Query $query, $whereInFile = null, $writeToFile = null)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::getRequestRead() does not have parameter type hint for its parameter $whereInFile but it should be possible to add it based on @param annotation "null|WhereInFile".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::getRequestRead() does not have parameter type hint for its parameter $writeToFile but it should be possible to add it based on @param annotation "null|WriteToFile".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::getRequestRead() does not have return type hint for its return value but it should be possible to add it based on @return annotation "CurlerRequest".
Loading history...
469
    {
470 38
        $urlParams = ['readonly' => 2];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
471 38
        $query_as_string = false;
472
        // ---------------------------------------------------------------------------------
473 38
        if ($whereInFile instanceof WhereInFile && $whereInFile->size()) {
474
            // $request = $this->prepareSelectWhereIn($request, $whereInFile);
475 1
            $structure = $whereInFile->fetchUrlParams();
476
            // $structure = [];
477 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...
478 1
            $query_as_string = true;
479
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
480
        // ---------------------------------------------------------------------------------
481
        // if result to file
482 38
        if ($writeToFile instanceof WriteToFile && $writeToFile->fetchFormat()) {
483 1
            $query->setFormat($writeToFile->fetchFormat());
484 1
            unset($urlParams['extremes']);
485
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
486
        // ---------------------------------------------------------------------------------
487
        // makeRequest read
488 38
        $request = $this->makeRequest($query, $urlParams, $query_as_string);
489
        // ---------------------------------------------------------------------------------
490
        // attach files
491 38
        if ($whereInFile instanceof WhereInFile && $whereInFile->size()) {
492 1
            $request->attachFiles($whereInFile->fetchFiles());
493
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
494
        // ---------------------------------------------------------------------------------
495
        // result to file
496 38
        if ($writeToFile instanceof WriteToFile && $writeToFile->fetchFormat()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
497
498 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...
499 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...
500
501 1
                $isGz = $writeToFile->getGzip();
502
503 1
                if ($isGz) {
504
                    // write gzip header
505
                    // "\x1f\x8b\x08\x00\x00\x00\x00\x00"
506
                    // fwrite($fout, "\x1F\x8B\x08\x08".pack("V", time())."\0\xFF", 10);
507
                    // write the original file name
508
                    // $oname = str_replace("\0", "", basename($writeToFile->fetchFile()));
509
                    // fwrite($fout, $oname."\0", 1+strlen($oname));
510
511
                    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...
512
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
513
                }
514
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
515
516
                $request->setResultFileHandle($fout, $isGz)->setCallbackFunction(function (CurlerRequest $request) {
0 ignored issues
show
introduced by
Closure not using "$this" should be declared static.
Loading history...
introduced by
Closure does not have void return type hint.
Loading history...
517
                    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...
518 1
                });
519
            }
520
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
521 38
        if ($this->xClickHouseProgress) {
522
            $request->setFunctionProgress([$this, '__findXClickHouseProgress']);
523
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
524
        // ---------------------------------------------------------------------------------
525 38
        return $request;
526
527
    }
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...
528
529 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...
530
    {
531 1
        $this->_query_degenerations = [];
532 1
        return true;
533
    }
534
535 66
    public function addQueryDegeneration(Degeneration $degeneration)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::addQueryDegeneration() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function addQueryDegeneration()
Loading history...
536
    {
537 66
        $this->_query_degenerations[] = $degeneration;
538 66
        return true;
539
    }
540
541
    /**
542
     * @param Query $query
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::getRequestWrite() has useless @param annotation for parameter $query.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
543
     * @return CurlerRequest
544
     * @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...
545
     */
546 26
    public function getRequestWrite(Query $query)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::getRequestWrite() does not have return type hint for its return value but it should be possible to add it based on @return annotation "CurlerRequest".
Loading history...
547
    {
548 26
        $urlParams = ['readonly' => 0];
549 26
        return $this->makeRequest($query, $urlParams);
550
    }
551
552
    /**
553
     * @throws TransportException
0 ignored issues
show
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
554
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
555 37
    public function ping(): bool
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
556
    {
557 37
        $request = new CurlerRequest();
558 37
        $request->url($this->getUri())->verbose(false)->GET()->connectTimeOut($this->getConnectTimeOut());
559 37
        $this->_curler->execOne($request);
560
561 37
        return $request->response()->body() === 'Ok.' . PHP_EOL;
562
    }
563
564
    /**
565
     * @param string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
566
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
567
     * @return Query
568
     */
569 44
    private function prepareQuery($sql, $bindings)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::prepareQuery() does not have parameter type hint for its parameter $sql but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::prepareQuery() does not have parameter type hint for its parameter $bindings but it should be possible to add it based on @param annotation "mixed[]".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::prepareQuery() does not have return type hint for its return value but it should be possible to add it based on @return annotation "Query".
Loading history...
Coding Style introduced by
Type hint "string" missing for $sql
Loading history...
Coding Style introduced by
Type hint "array" missing for $bindings
Loading history...
570
    {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
571
572
        // add Degeneration query
573 44
        foreach ($this->_query_degenerations as $degeneration) {
574 44
            $degeneration->bindParams($bindings);
575
        }
576
577 44
        return new Query($sql, $this->_query_degenerations);
578
    }
579
580
581
    /**
582
     * @param Query|string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
583
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
584
     * @param null|WhereInFile $whereInFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
585
     * @param null|WriteToFile $writeToFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
586
     * @return CurlerRequest
587
     * @throws \Exception
0 ignored issues
show
introduced by
Class \Exception should not be referenced via a fully qualified name, but via a use statement.
Loading history...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
588
     */
589 37
    private function prepareSelect($sql, $bindings, $whereInFile, $writeToFile = null)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::prepareSelect() does not have return type hint for its return value but it should be possible to add it based on @return annotation "CurlerRequest".
Loading history...
Coding Style introduced by
Type hint "array" missing for $bindings
Loading history...
590
    {
591 37
        if ($sql instanceof Query) {
592
            return $this->getRequestWrite($sql);
593
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
594 37
        $query = $this->prepareQuery($sql, $bindings);
595 37
        $query->setFormat('JSON');
596 37
        return $this->getRequestRead($query, $whereInFile, $writeToFile);
597
    }
598
599
600
    /**
601
     * @param Query|string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
602
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
603
     * @return CurlerRequest
604
     * @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...
605
     */
606 27
    private function prepareWrite($sql, $bindings = [])
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::prepareWrite() does not have return type hint for its return value but it should be possible to add it based on @return annotation "CurlerRequest".
Loading history...
Coding Style introduced by
Type hint "array" missing for $bindings
Loading history...
607
    {
608 27
        if ($sql instanceof Query) {
609
            return $this->getRequestWrite($sql);
610
        }
611
612 27
        $query = $this->prepareQuery($sql, $bindings);
613 26
        return $this->getRequestWrite($query);
614
    }
615
616
    /**
617
     * @return bool
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
618
     * @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...
619
     */
620 10
    public function executeAsync()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::executeAsync() does not have return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
621
    {
622 10
        return $this->_curler->execLoopWait();
623
    }
624
625
    /**
626
     * @param Query|string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
627
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
628
     * @param null|WhereInFile $whereInFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
629
     * @param null|WriteToFile $writeToFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
630
     * @return Statement
631
     * @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...
632
     * @throws \Exception
0 ignored issues
show
introduced by
Class \Exception should not be referenced via a fully qualified name, but via a use statement.
Loading history...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
633
     */
634 30
    public function select($sql, array $bindings = [], $whereInFile = null, $writeToFile = null)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::select() does not have return type hint for its return value but it should be possible to add it based on @return annotation "Statement".
Loading history...
635
    {
636 30
        $request = $this->prepareSelect($sql, $bindings, $whereInFile, $writeToFile);
637 30
        $this->_curler->execOne($request);
638 30
        return new Statement($request);
639
    }
640
641
    /**
642
     * @param Query|string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
643
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
644
     * @param null|WhereInFile $whereInFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
645
     * @param null|WriteToFile $writeToFile
0 ignored issues
show
introduced by
Null type hint should be on last position.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
646
     * @return Statement
647
     * @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...
648
     * @throws \Exception
0 ignored issues
show
introduced by
Class \Exception should not be referenced via a fully qualified name, but via a use statement.
Loading history...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
649
     */
650 7
    public function selectAsync($sql, array $bindings = [], $whereInFile = null, $writeToFile = null)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::selectAsync() does not have return type hint for its return value but it should be possible to add it based on @return annotation "Statement".
Loading history...
651
    {
652 7
        $request = $this->prepareSelect($sql, $bindings, $whereInFile, $writeToFile);
653 7
        $this->_curler->addQueLoop($request);
654 7
        return new Statement($request);
655
    }
656
657
    /**
658
     * @param callable $callback
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
659
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
660
    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...
661
    {
662
        $this->xClickHouseProgress = $callback;
663
    }
664
665
    /**
666
     * @param string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
667
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
668
     * @param bool $exception
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "boolean" but found "bool" for parameter type
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
669
     * @return Statement
670
     * @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...
671
     */
672 27
    public function write($sql, array $bindings = [], $exception = true)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::write() does not have parameter type hint for its parameter $sql but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::write() does not have parameter type hint for its parameter $exception but it should be possible to add it based on @param annotation "bool".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::write() does not have return type hint for its return value but it should be possible to add it based on @return annotation "Statement".
Loading history...
Coding Style introduced by
Type hint "string" missing for $sql
Loading history...
Coding Style introduced by
Type hint "bool" missing for $exception
Loading history...
673
    {
674 27
        $request = $this->prepareWrite($sql, $bindings);
675 26
        $this->_curler->execOne($request);
676 26
        $response = new Statement($request);
677 26
        if ($exception) {
678 26
            if ($response->isError()) {
679 3
                $response->error();
680
            }
681
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
682 24
        return $response;
683
    }
684
685
    /**
686
     * @param Stream $streamRW
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::streaming() has useless @param annotation for parameter $streamRW.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
687
     * @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...
688
     * @return Statement
689
     * @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...
690
     */
691 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...
692
    {
693 2
        $callable = $streamRW->getClosure();
694 2
        $stream = $streamRW->getStream();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
695
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
696
697
        try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
698
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
699
700 2
            if (!is_callable($callable)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
introduced by
Function is_callable() should not be referenced via a fallback global name, but via a use statement.
Loading history...
701
                if ($streamRW->isWrite()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
702
703
                    $callable = function ($ch, $fd, $length) use ($stream) {
0 ignored issues
show
introduced by
Closure not using "$this" should be declared static.
Loading history...
704
                        return ($line = fread($stream, $length)) ? $line : '';
0 ignored issues
show
introduced by
Useless parentheses.
Loading history...
introduced by
Function fread() should not be referenced via a fallback global name, but via a use statement.
Loading history...
705
                    };
706
                } else {
707
                    $callable = function ($ch, $fd) use ($stream) {
0 ignored issues
show
introduced by
Closure not using "$this" should be declared static.
Loading history...
708
                        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...
709
                    };
710
                }
711
            }
712
713 2
            if ($streamRW->isGzipHeader()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
714
715 1
                if ($streamRW->isWrite()) {
716 1
                    $request->header('Content-Encoding', 'gzip');
717 1
                    $request->header('Content-Type', 'application/x-www-form-urlencoded');
718
                } else {
719
                    $request->header('Accept-Encoding', 'gzip');
720
                }
0 ignored issues
show
Coding Style introduced by
Blank line found after control structure
Loading history...
721
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
722
            }
723
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
724
725 2
            $request->header('Transfer-Encoding', 'chunked');
726
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
727
728 2
            if ($streamRW->isWrite()) {
729 1
                $request->setReadFunction($callable);
730
            } else {
731 1
                $request->setWriteFunction($callable);
732
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
733
734
//                $request->setHeaderFunction($callableHead);
735
            }
736
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
737
738 2
            $this->_curler->execOne($request, true);
739 2
            $response = new Statement($request);
740 2
            if ($response->isError()) {
741
                $response->error();
742
            }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
743 2
            return $response;
744
        } finally {
745 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...
746 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...
747
        }
748
749
750
    }
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...
751
752
753
    /**
754
     * @param Stream $streamRead
755
     * @param string $sql
756
     * @param mixed[] $bindings
757
     * @return Statement
758
     * @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...
759
     */
760 1
    public function streamRead(Stream $streamRead, $sql, $bindings = [])
761
    {
762 1
        $sql = $this->prepareQuery($sql, $bindings);
763 1
        $request = $this->getRequestRead($sql);
764 1
        return $this->streaming($streamRead, $request);
765
766
    }
767
768
    /**
769
     * @param Stream $streamWrite
770
     * @param string $sql
771
     * @param mixed[] $bindings
772
     * @return Statement
773
     * @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...
774
     */
775 1
    public function streamWrite(Stream $streamWrite, $sql, $bindings = [])
776
    {
777 1
        $sql = $this->prepareQuery($sql, $bindings);
778 1
        $request = $this->writeStreamData($sql);
779 1
        return $this->streaming($streamWrite, $request);
780
    }
781
}
782