Passed
Push — master ( b10cd9...e8febd )
by Igor
10:12 queued 07:01
created

Http::newRequest()   B

Complexity

Conditions 6
Paths 24

Size

Total Lines 38
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 6.6393

Importance

Changes 8
Bugs 1 Features 2
Metric Value
cc 6
eloc 23
c 8
b 1
f 2
nc 24
nop 1
dl 0
loc 38
ccs 17
cts 23
cp 0.7391
crap 6.6393
rs 8.9297
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
introduced by
Method \ClickHouseDB\Transport\Http::__construct() has useless @param annotation for parameter $authMethod.
Loading history...
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, int $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
Parameter $authMethod has null default value, but is not marked as nullable.
Loading history...
103
    {
104 66
        $this->setHost($host, $port);
105
106 66
        $this->_username = $username;
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...
107 66
        $this->_password = $password;
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...
108 66
        $this->_authMethod = $authMethod;
109 66
        $this->_settings = new Settings($this);
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...
110
111 66
        $this->setCurler();
112 66
    }
113
114
115 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...
116
    {
117 66
        $this->_curler = new CurlerRolling();
118 66
    }
119
120
    /**
121
     * @param CurlerRolling $curler
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
122
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
123
    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...
124
    {
125
        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...
126
            $this->_curler = $curler;
127
        }
128
    }
129
130
    /**
131
     * @return CurlerRolling
132
     */
133
    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...
134
    {
135
        return $this->_curler;
136
    }
137
138
    /**
139
     * @param string $host
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
140
     * @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...
141
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
142 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...
143
    {
144 66
        if ($port > 0) {
145 66
            $this->_port = $port;
146
        }
147
148 66
        $this->_host = $host;
149 66
    }
150
151
    /**
152
     * Sets client SSL certificate for Yandex Cloud
153
     *
154
     * @param string $caPath
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
155
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
156
    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...
157
    {
158
        $this->sslCA = $caPath;
159
    }
160
161
    /**
162
     * @return string
163
     */
164 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...
165
    {
166 53
        $proto = 'http';
167 53
        if ($this->settings()->isHttps()) {
168 1
            $proto = 'https';
169
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
170 53
        $uri = $proto . '://' . $this->_host;
171 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...
172 1
            return $uri;
173
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
174 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...
175 53
            return $uri . ':' . $this->_port;
176
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
177 1
        return $uri;
178
    }
179
180
    /**
181
     * @return Settings
182
     */
183 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...
184
    {
185 66
        return $this->_settings;
186
    }
187
188
    /**
189
     * @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...
190
     * @return mixed
191
     */
192
    public function verbose($flag)
193
    {
194
        $this->_verbose = $flag;
195
        return $flag;
196
    }
197
198
    /**
199
     * @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...
200
     * @return string
201
     */
202 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...
203
    {
204 43
        $settings = $this->settings()->getSettings();
205
206 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...
207 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...
208
        }
209
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
210
211 43
        if ($this->settings()->isReadOnlyUser()) {
212
            unset($settings['extremes']);
213
            unset($settings['readonly']);
214
            unset($settings['enable_http_compression']);
215
            unset($settings['max_execution_time']);
216
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
217
        }
218
219 43
        unset($settings['https']);
220
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
221
222 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...
223
    }
224
225
    /**
226
     * @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...
227
     * @return CurlerRequest
228
     */
229 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...
230
    {
231 43
        $new = new CurlerRequest();
232
233 43
        switch ($this->_authMethod) {
234 43
            case self::AUTH_METHOD_QUERY_STRING:
235
                /* @todo: Move this implementation to CurlerRequest class. Possible options: the authentication method
236
                 *        should be applied in method `CurlerRequest:prepareRequest()`.
237
                 */
238
                $this->settings()->set('user', $this->_username);
239
                $this->settings()->set('password', $this->_password);
240
                break;
241 43
            case self::AUTH_METHOD_BASIC_AUTH:
242
                $new->authByBasicAuth($this->_username, $this->_password);
243
                break;
244
            default:
245
                // Auth with headers by default
246 43
                $new->authByHeaders($this->_username, $this->_password);
247 43
                break;
248
        }
249
250 43
        $new->POST()->setRequestExtendedInfo($extendinfo);
251
252 43
        if ($this->settings()->isEnableHttpCompression()) {
253 43
            $new->httpCompression(true);
254
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
255 43
        if ($this->settings()->getSessionId()) {
256 1
            $new->persistent();
257
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
258 43
        if ($this->sslCA) {
259
            $new->setSslCa($this->sslCA);
260
        }
261
262 43
        $new->timeOut($this->settings()->getTimeOut());
263 43
        $new->connectTimeOut($this->_connectTimeOut);//->keepAlive(); // one sec
264 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...
265
266 43
        return $new;
267
    }
268
269
    /**
270
     * @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...
271
     * @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...
272
     * @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...
273
     * @return CurlerRequest
274
     * @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...
275
     */
276 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...
277
    {
278 43
        $sql = $query->toSql();
279
280 43
        if ($query_as_string) {
281 1
            $urlParams['query'] = $sql;
282
        }
283
284
        $extendinfo = [
285 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...
286 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...
287 43
            'format' => $query->getFormat()
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
288
        ];
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 22 space(s), but found 8.
Loading history...
289
290 43
        $new = $this->newRequest($extendinfo);
291
292
        /*
293
         * Build URL after request making, since URL may contain auth data. This will not matter after the
294
         * implantation of the todo in the `HTTP:newRequest()` method.
295
         */
296 43
        $url = $this->getUrl($urlParams);
297 43
        $new->url($url);
298
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
299
300 43
        if (!$query_as_string) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
301 43
            $new->parameters_json($sql);
302
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
303 43
        if ($this->settings()->isEnableHttpCompression()) {
304 43
            $new->httpCompression(true);
305
        }
306
307 43
        return $new;
308
    }
309
310
    /**
311
     * @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...
312
     * @return CurlerRequest
313
     */
314 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...
315
    {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
316
317 3
        if ($sql instanceof Query) {
318 1
            $query = $sql;
319
        } else {
320 2
            $query = new Query($sql);
321
        }
322
323
        $extendinfo = [
324 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...
325 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...
326 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...
327
        ];
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...
328
329 3
        $request = $this->newRequest($extendinfo);
330
331
        /*
332
         * Build URL after request making, since URL may contain auth data. This will not matter after the
333
         * implantation of the todo in the `HTTP:newRequest()` method.
334
         */
335 3
        $url = $this->getUrl([
336 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...
337 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...
338
        ]);
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...
339
340 3
        $request->url($url);
341 3
        return $request;
342
    }
343
344
345
    /**
346
     * @param string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
347
     * @param string $file_name
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
348
     * @return Statement
349
     * @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...
350
     */
351 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...
352
    {
353 8
        $query = new Query($sql);
354
355
        $extendinfo = [
356 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...
357 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...
358 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...
359
        ];
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...
360
361 8
        $request = $this->newRequest($extendinfo);
362
363
        /*
364
         * Build URL after request making, since URL may contain auth data. This will not matter after the
365
         * implantation of the todo in the `HTTP:newRequest()` method.
366
         */
367 8
        $url = $this->getUrl([
368 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...
369 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...
370
        ]);
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...
371
372 8
        $request->url($url);
373
374
        $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...
375 8
            $handle = $request->getInfileHandle();
376 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...
377 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...
378
            }
379 8
        });
380
381 8
        $request->setInfile($file_name);
382 8
        $this->_curler->addQueLoop($request);
383
384 8
        return new Statement($request);
385
    }
386
387
    /**
388
     * get Count Pending Query in Queue
389
     *
390
     * @return int
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for function return type
Loading history...
391
     */
392 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...
393
    {
394 12
        return $this->_curler->countPending();
395
    }
396
397
    /**
398
     * set Connect TimeOut in seconds [CURLOPT_CONNECTTIMEOUT] ( int )
399
     *
400
     * @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...
401
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
402 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...
403
    {
404 2
        $this->_connectTimeOut = $connectTimeOut;
405 2
    }
406
407
    /**
408
     * get ConnectTimeOut in seconds
409
     *
410
     * @return int
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for function return type
Loading history...
411
     */
412 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...
413
    {
414 37
        return $this->_connectTimeOut;
415
    }
416
417
418
    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...
419
    {
420
        $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...
421
422
        // Search X-ClickHouse-Progress
423
        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...
424
            $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...
425
            $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...
426
            if (!$header_size) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
427
                return false;
428
            }
429
430
            $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...
431
            if (!$header_size) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
432
                return false;
433
            }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
434
            $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...
435
436
            if (!$pos) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
437
                return false;
438
            }
439
440
            $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...
441
            $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...
442
443
            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...
444
445
                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...
446
                    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...
447
                } else {
448
                    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...
449
                }
0 ignored issues
show
Coding Style introduced by
Blank line found after control structure
Loading history...
450
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
451
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
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
Blank line found at end of control structure
Loading history...
454
        }
455
456
    }
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...
457
458
    /**
459
     * @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...
460
     * @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...
461
     * @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...
462
     * @return CurlerRequest
463
     * @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...
464
     */
465 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...
466
    {
467 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...
468 38
        $query_as_string = false;
469
        // ---------------------------------------------------------------------------------
470 38
        if ($whereInFile instanceof WhereInFile && $whereInFile->size()) {
471
            // $request = $this->prepareSelectWhereIn($request, $whereInFile);
472 1
            $structure = $whereInFile->fetchUrlParams();
473
            // $structure = [];
474 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...
475 1
            $query_as_string = true;
476
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
477
        // ---------------------------------------------------------------------------------
478
        // if result to file
479 38
        if ($writeToFile instanceof WriteToFile && $writeToFile->fetchFormat()) {
480 1
            $query->setFormat($writeToFile->fetchFormat());
481 1
            unset($urlParams['extremes']);
482
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
483
        // ---------------------------------------------------------------------------------
484
        // makeRequest read
485 38
        $request = $this->makeRequest($query, $urlParams, $query_as_string);
486
        // ---------------------------------------------------------------------------------
487
        // attach files
488 38
        if ($whereInFile instanceof WhereInFile && $whereInFile->size()) {
489 1
            $request->attachFiles($whereInFile->fetchFiles());
490
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
491
        // ---------------------------------------------------------------------------------
492
        // result to file
493 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...
494
495 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...
496 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...
497
498 1
                $isGz = $writeToFile->getGzip();
499
500 1
                if ($isGz) {
501
                    // write gzip header
502
                    // "\x1f\x8b\x08\x00\x00\x00\x00\x00"
503
                    // fwrite($fout, "\x1F\x8B\x08\x08".pack("V", time())."\0\xFF", 10);
504
                    // write the original file name
505
                    // $oname = str_replace("\0", "", basename($writeToFile->fetchFile()));
506
                    // fwrite($fout, $oname."\0", 1+strlen($oname));
507
508
                    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...
509
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
510
                }
511
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
512
513
                $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...
514
                    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...
515 1
                });
516
            }
517
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
518 38
        if ($this->xClickHouseProgress) {
519
            $request->setFunctionProgress([$this, '__findXClickHouseProgress']);
520
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
521
        // ---------------------------------------------------------------------------------
522 38
        return $request;
523
524
    }
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...
525
526 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...
527
    {
528 1
        $this->_query_degenerations = [];
529 1
        return true;
530
    }
531
532 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...
533
    {
534 66
        $this->_query_degenerations[] = $degeneration;
535 66
        return true;
536
    }
537
538
    /**
539
     * @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...
540
     * @return CurlerRequest
541
     * @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...
542
     */
543 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...
544
    {
545 26
        $urlParams = ['readonly' => 0];
546 26
        return $this->makeRequest($query, $urlParams);
547
    }
548
549
    /**
550
     * @throws TransportException
0 ignored issues
show
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
551
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
552 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...
553
    {
554 37
        $request = new CurlerRequest();
555 37
        $request->url($this->getUri())->verbose(false)->GET()->connectTimeOut($this->getConnectTimeOut());
556 37
        $this->_curler->execOne($request);
557
558 37
        return $request->response()->body() === 'Ok.' . PHP_EOL;
559
    }
560
561
    /**
562
     * @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...
563
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
564
     * @return Query
565
     */
566 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...
567
    {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
568
569
        // add Degeneration query
570 44
        foreach ($this->_query_degenerations as $degeneration) {
571 44
            $degeneration->bindParams($bindings);
572
        }
573
574 44
        return new Query($sql, $this->_query_degenerations);
575
    }
576
577
578
    /**
579
     * @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...
580
     * @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...
581
     * @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...
582
     * @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...
583
     * @return CurlerRequest
584
     * @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...
585
     */
586 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...
587
    {
588 37
        if ($sql instanceof Query) {
589
            return $this->getRequestWrite($sql);
590
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
591 37
        $query = $this->prepareQuery($sql, $bindings);
592 37
        $query->setFormat('JSON');
593 37
        return $this->getRequestRead($query, $whereInFile, $writeToFile);
594
    }
595
596
597
    /**
598
     * @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...
599
     * @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...
600
     * @return CurlerRequest
601
     * @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...
602
     */
603 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...
604
    {
605 27
        if ($sql instanceof Query) {
606
            return $this->getRequestWrite($sql);
607
        }
608
609 27
        $query = $this->prepareQuery($sql, $bindings);
610 26
        return $this->getRequestWrite($query);
611
    }
612
613
    /**
614
     * @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...
615
     * @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...
616
     */
617 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...
618
    {
619 10
        return $this->_curler->execLoopWait();
620
    }
621
622
    /**
623
     * @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...
624
     * @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...
625
     * @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...
626
     * @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...
627
     * @return Statement
628
     * @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...
629
     * @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...
630
     */
631 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...
632
    {
633 30
        $request = $this->prepareSelect($sql, $bindings, $whereInFile, $writeToFile);
634 30
        $this->_curler->execOne($request);
635 30
        return new Statement($request);
636
    }
637
638
    /**
639
     * @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...
640
     * @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...
641
     * @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...
642
     * @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...
643
     * @return Statement
644
     * @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...
645
     * @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...
646
     */
647 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...
648
    {
649 7
        $request = $this->prepareSelect($sql, $bindings, $whereInFile, $writeToFile);
650 7
        $this->_curler->addQueLoop($request);
651 7
        return new Statement($request);
652
    }
653
654
    /**
655
     * @param callable $callback
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
656
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
657
    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...
658
    {
659
        $this->xClickHouseProgress = $callback;
660
    }
661
662
    /**
663
     * @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...
664
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
665
     * @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...
666
     * @return Statement
667
     * @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...
668
     */
669 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...
670
    {
671 27
        $request = $this->prepareWrite($sql, $bindings);
672 26
        $this->_curler->execOne($request);
673 26
        $response = new Statement($request);
674 26
        if ($exception) {
675 26
            if ($response->isError()) {
676 3
                $response->error();
677
            }
678
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
679 24
        return $response;
680
    }
681
682
    /**
683
     * @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...
684
     * @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...
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...
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
687
     */
688 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...
689
    {
690 2
        $callable = $streamRW->getClosure();
691 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...
692
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
693
694
        try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
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 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...
698
                if ($streamRW->isWrite()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
699
700
                    $callable = function ($ch, $fd, $length) use ($stream) {
0 ignored issues
show
introduced by
Closure not using "$this" should be declared static.
Loading history...
701
                        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...
702
                    };
703
                } else {
704
                    $callable = function ($ch, $fd) use ($stream) {
0 ignored issues
show
introduced by
Closure not using "$this" should be declared static.
Loading history...
705
                        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...
706
                    };
707
                }
708
            }
709
710 2
            if ($streamRW->isGzipHeader()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
711
712 1
                if ($streamRW->isWrite()) {
713 1
                    $request->header('Content-Encoding', 'gzip');
714 1
                    $request->header('Content-Type', 'application/x-www-form-urlencoded');
715
                } else {
716
                    $request->header('Accept-Encoding', 'gzip');
717
                }
0 ignored issues
show
Coding Style introduced by
Blank line found after control structure
Loading history...
718
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
719
            }
720
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
721
722 2
            $request->header('Transfer-Encoding', 'chunked');
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
            if ($streamRW->isWrite()) {
726 1
                $request->setReadFunction($callable);
727
            } else {
728 1
                $request->setWriteFunction($callable);
729
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
730
731
//                $request->setHeaderFunction($callableHead);
732
            }
733
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
734
735 2
            $this->_curler->execOne($request, true);
736 2
            $response = new Statement($request);
737 2
            if ($response->isError()) {
738
                $response->error();
739
            }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
740 2
            return $response;
741
        } finally {
742 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...
743 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...
744
        }
745
746
747
    }
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...
748
749
750
    /**
751
     * @param Stream $streamRead
752
     * @param string $sql
753
     * @param mixed[] $bindings
754
     * @return Statement
755
     * @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...
756
     */
757 1
    public function streamRead(Stream $streamRead, $sql, $bindings = [])
758
    {
759 1
        $sql = $this->prepareQuery($sql, $bindings);
760 1
        $request = $this->getRequestRead($sql);
761 1
        return $this->streaming($streamRead, $request);
762
763
    }
764
765
    /**
766
     * @param Stream $streamWrite
767
     * @param string $sql
768
     * @param mixed[] $bindings
769
     * @return Statement
770
     * @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...
771
     */
772 1
    public function streamWrite(Stream $streamWrite, $sql, $bindings = [])
773
    {
774 1
        $sql = $this->prepareQuery($sql, $bindings);
775 1
        $request = $this->writeStreamData($sql);
776 1
        return $this->streaming($streamWrite, $request);
777
    }
778
}
779