Failed Conditions
Push — master ( 12bd2a...8e4b2b )
by Igor
03:12
created

Http::setDirtyCurler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 6
rs 10
1
<?php
0 ignored issues
show
introduced by
An error occurred during processing; checking has been aborted. The error message was: "if" without curly braces is not supported.
Loading history...
introduced by
Missing declare(strict_types=1).
Loading history...
2
3
namespace ClickHouseDB\Transport;
4
5
use ClickHouseDB\Exception\TransportException;
6
use ClickHouseDB\Query\Degeneration;
7
use ClickHouseDB\Query\Query;
8
use ClickHouseDB\Query\WhereInFile;
9
use ClickHouseDB\Query\WriteToFile;
10
use ClickHouseDB\Settings;
11
use ClickHouseDB\Statement;
12
use const PHP_EOL;
13
14
class Http
15
{
16
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_username with single line content, use one-line comment instead.
Loading history...
17
     * @var string
18
     */
19
    private $_username = null;
20
21
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_password with single line content, use one-line comment instead.
Loading history...
22
     * @var string
23
     */
24
    private $_password = null;
25
26
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_host with single line content, use one-line comment instead.
Loading history...
27
     * @var string
28
     */
29
    private $_host = '';
30
31
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_port with single line content, use one-line comment instead.
Loading history...
32
     * @var int
33
     */
34
    private $_port = 0;
35
36
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_verbose with single line content, use one-line comment instead.
Loading history...
37
     * @var bool|int
38
     */
39
    private $_verbose = false;
40
41
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_curler with single line content, use one-line comment instead.
Loading history...
42
     * @var CurlerRolling
43
     */
44
    private $_curler = null;
45
46
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_settings with single line content, use one-line comment instead.
Loading history...
47
     * @var Settings
48
     */
49
    private $_settings = null;
50
51
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$_query_degenerations with single line content, use one-line comment instead.
Loading history...
52
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Transport\Http::$_query_degenerations does not specify type hint for its items.
Loading history...
53
     */
54
    private $_query_degenerations = [];
55
56
    /**
57
     * Count seconds (int)
58
     *
59
     * @var int
60
     */
61
    private $_connectTimeOut = 5;
62
63
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\Http::$xClickHouseProgress with single line content, use one-line comment instead.
Loading history...
64
     * @var callable
65
     */
66
    private $xClickHouseProgress = null;
67
68
    /**
69
     * Http constructor.
0 ignored issues
show
introduced by
Documentation comment contains forbidden comment "Http constructor.".
Loading history...
70
     * @param string $host
0 ignored issues
show
introduced by
Expected 1 lines between description and annotations, found 0.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
71
     * @param int $port
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
72
     * @param string $username
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
73
     * @param string $password
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
74
     */
75 67
    public function __construct($host, $port, $username, $password)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::__construct() does not have parameter type hint for its parameter $host but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::__construct() does not have parameter type hint for its parameter $port but it should be possible to add it based on @param annotation "int".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::__construct() does not have parameter type hint for its parameter $username but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::__construct() does not have parameter type hint for its parameter $password but it should be possible to add it based on @param annotation "string".
Loading history...
Coding Style introduced by
Type hint "string" missing for $host
Loading history...
Coding Style introduced by
Type hint "int" missing for $port
Loading history...
Coding Style introduced by
Type hint "string" missing for $username
Loading history...
Coding Style introduced by
Type hint "string" missing for $password
Loading history...
76
    {
77 67
        $this->setHost($host, $port);
78
79 67
        $this->_username = $username;
80 67
        $this->_password = $password;
81 67
        $this->_settings = new Settings($this);
82
83 67
        $this->setCurler();
84 67
    }
85
86
87 67
    public function setCurler()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::setCurler() does not have void return type hint.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function setCurler()
Loading history...
88
    {
89 67
        $this->_curler = new CurlerRolling();
90 67
    }
91
92
    /**
93
     * @param CurlerRolling $curler
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
94
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
95
    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...
96
        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...
97
            $this->_curler = $curler;
98
        }
99
    }
100
101
    /**
102
     * @return CurlerRolling
103
     */
104
    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...
105
    {
106
        return $this->_curler;
107
    }
108
109
    /**
110
     * @param string $host
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
111
     * @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...
112
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
113 67
    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...
114
    {
115 67
        if ($port > 0) {
116 67
            $this->_port = $port;
117
        }
118
119 67
        $this->_host = $host;
120 67
    }
121
122
    /**
123
     * @return string
124
     */
125 54
    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...
126
    {
127 54
        $proto = 'http';
128 54
        if ($this->settings()->isHttps()) {
129 1
            $proto = 'https';
130
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
131 54
        $uri = $proto . '://' . $this->_host;
132 54
        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...
133 1
            return $uri;
134
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
135 54
        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...
136 54
            return $uri . ':' . $this->_port;
137
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
138 1
        return $uri;
139
    }
140
141
    /**
142
     * @return Settings
143
     */
144 67
    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...
145
    {
146 67
        return $this->_settings;
147
    }
148
149
    /**
150
     * @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...
151
     * @return mixed
152
     */
153
    public function verbose($flag)
154
    {
155
        $this->_verbose = $flag;
156
        return $flag;
157
    }
158
159
    /**
160
     * @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...
161
     * @return string
162
     */
163 44
    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...
164
    {
165 44
        $settings = $this->settings()->getSettings();
166
167 44
        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...
168 44
            $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...
169
        }
170
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
171
172 44
        if ($this->settings()->isReadOnlyUser())
173
        {
174
            unset($settings['extremes']);
175
            unset($settings['readonly']);
176
            unset($settings['enable_http_compression']);
177
            unset($settings['max_execution_time']);
178
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
179
        }
180
181 44
        unset($settings['https']);
182
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
183
184 44
        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...
185
    }
186
187
    /**
188
     * @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...
189
     * @return CurlerRequest
190
     */
191 44
    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...
192
    {
193 44
        $new = new CurlerRequest();
194 44
        $new->auth($this->_username, $this->_password)
195 44
            ->POST()
196 44
            ->setRequestExtendedInfo($extendinfo);
197
198 44
        if ($this->settings()->isEnableHttpCompression()) {
199 44
            $new->httpCompression(true);
200
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
201 44
        if ($this->settings()->getSessionId())
202
        {
203 1
            $new->persistent();
204
        }
205
206 44
        $new->timeOut($this->settings()->getTimeOut());
207 44
        $new->connectTimeOut($this->_connectTimeOut);//->keepAlive(); // one sec
208 44
        $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...
209
210 44
        return $new;
211
    }
212
213
    /**
214
     * @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...
215
     * @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...
216
     * @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...
217
     * @return CurlerRequest
218
     * @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...
219
     */
220 44
    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...
221
    {
222 44
        $sql = $query->toSql();
223
224 44
        if ($query_as_string) {
225 1
            $urlParams['query'] = $sql;
226
        }
227
228 44
        $url = $this->getUrl($urlParams);
229
230
        $extendinfo = [
231 44
            '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...
232 44
            '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...
233 44
            'format'=> $query->getFormat()
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 1 space(s) but found 0
Loading history...
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
234
        ];
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...
235
236 44
        $new = $this->newRequest($extendinfo);
237 44
        $new->url($url);
238
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 4 empty lines
Loading history...
239
240
241
242 44
        if (!$query_as_string) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
243 44
            $new->parameters_json($sql);
244
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
245 44
        if ($this->settings()->isEnableHttpCompression()) {
246 44
            $new->httpCompression(true);
247
        }
248
249 44
        return $new;
250
    }
251
252
    /**
253
     * @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...
254
     * @return CurlerRequest
255
     */
256 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...
257
    {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
258
259 3
        if ($sql instanceof Query) {
260 1
            $query=$sql;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
261
        } else {
262 2
            $query = new Query($sql);
263
        }
264
265 3
        $url = $this->getUrl([
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

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

To visualize

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

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

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

will produce no issues.

Loading history...
266 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...
267 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...
268
        ]);
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...
269
        $extendinfo = [
270 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...
271 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...
272 3
            'format'=> $query->getFormat()
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 23 spaces, but found 12.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 1 space(s) but found 0
Loading history...
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
273
        ];
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...
274
275 3
        $request = $this->newRequest($extendinfo);
276 3
        $request->url($url);
277 3
        return $request;
278
    }
279
280
281
    /**
282
     * @param string $sql
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
283
     * @param string $file_name
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
284
     * @return Statement
285
     * @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...
286
     */
287 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...
288
    {
289 8
        $query = new Query($sql);
290
291 8
        $url = $this->getUrl([
292 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...
293 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...
294
        ]);
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...
295
296
        $extendinfo = [
297 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...
298 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...
299 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
Array double arrow not aligned correctly; expected 1 space(s) but found 0
Loading history...
introduced by
MultiLine arrays must have a trailing comma after the last element.
Loading history...
300
        ];
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...
301
302 8
        $request = $this->newRequest($extendinfo);
303 8
        $request->url($url);
304
305
        $request->setCallbackFunction(function(CurlerRequest $request) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
introduced by
Closure not using "$this" should be declared static.
Loading history...
introduced by
Closure does not have void return type hint.
Loading history...
306 8
            $handle = $request->getInfileHandle();
307 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...
308 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...
309
            }
310 8
        });
311
312 8
        $request->setInfile($file_name);
313 8
        $this->_curler->addQueLoop($request);
314
315 8
        return new Statement($request);
316
    }
317
318
    /**
319
     * get Count Pending Query in Queue
320
     *
321
     * @return int
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for function return type
Loading history...
322
     */
323 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...
324
    {
325 12
        return $this->_curler->countPending();
326
    }
327
328
    /**
329
     * set Connect TimeOut in seconds [CURLOPT_CONNECTTIMEOUT] ( int )
330
     *
331
     * @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...
332
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
333 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...
334
    {
335 2
        $this->_connectTimeOut = $connectTimeOut;
336 2
    }
337
338
    /**
339
     * get ConnectTimeOut in seconds
340
     *
341
     * @return int
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for function return type
Loading history...
342
     */
343 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...
344
    {
345 37
        return $this->_connectTimeOut;
346
    }
347
348
349 1
    public function __findXClickHouseProgress($handle)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::__findXClickHouseProgress() does not have parameter type hint nor @param annotation for its parameter $handle.
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::__findXClickHouseProgress() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function __findXClickHouseProgress()
Loading history...
350
    {
351 1
        $code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
0 ignored issues
show
introduced by
Function curl_getinfo() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Constant CURLINFO_HTTP_CODE should not be referenced via a fallback global name, but via a use statement.
Loading history...
352
353
        // Search X-ClickHouse-Progress
354 1
        if ($code == 200) {
0 ignored issues
show
introduced by
Use early exit to reduce code nesting.
Loading history...
introduced by
Operator == is disallowed, use === instead.
Loading history...
355 1
            $response = curl_multi_getcontent($handle);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

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

To visualize

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

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

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

will produce no issues.

Loading history...
introduced by
Function curl_multi_getcontent() should not be referenced via a fallback global name, but via a use statement.
Loading history...
356 1
            $header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
0 ignored issues
show
introduced by
Function curl_getinfo() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Constant CURLINFO_HEADER_SIZE should not be referenced via a fallback global name, but via a use statement.
Loading history...
357 1
            if (!$header_size) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
358
                return false;
359
            }
360
361 1
            $header = substr($response, 0, $header_size);
0 ignored issues
show
introduced by
Function substr() should not be referenced via a fallback global name, but via a use statement.
Loading history...
362 1
            if (!$header_size) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
363
                return false;
364
            }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
365 1
            $pos = strrpos($header, 'X-ClickHouse-Progress');
0 ignored issues
show
introduced by
Function strrpos() should not be referenced via a fallback global name, but via a use statement.
Loading history...
366
367 1
            if (!$pos) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
368
                return false;
369
            }
370
371 1
            $last = substr($header, $pos);
0 ignored issues
show
introduced by
Function substr() should not be referenced via a fallback global name, but via a use statement.
Loading history...
372 1
            $data = @json_decode(str_ireplace('X-ClickHouse-Progress:', '', $last), true);
0 ignored issues
show
introduced by
Function json_decode() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Function str_ireplace() should not be referenced via a fallback global name, but via a use statement.
Loading history...
373
374 1
            if ($data && is_callable($this->xClickHouseProgress)) {
0 ignored issues
show
introduced by
Function is_callable() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
375
376 1
                if (is_array($this->xClickHouseProgress)) {
0 ignored issues
show
introduced by
Function is_array() should not be referenced via a fallback global name, but via a use statement.
Loading history...
377
                    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...
378
                } else {
379 1
                    call_user_func($this->xClickHouseProgress, $data);
0 ignored issues
show
introduced by
Function call_user_func() should not be referenced via a fallback global name, but via a use statement.
Loading history...
380
                }
0 ignored issues
show
Coding Style introduced by
Blank line found after control structure
Loading history...
381
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
382
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
383
            }
0 ignored issues
show
Coding Style introduced by
Blank line found after control structure
Loading history...
384
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
385
        }
386
387 1
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
388
389
    /**
390
     * @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...
391
     * @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...
392
     * @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...
393
     * @return CurlerRequest
394
     * @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...
395
     */
396 39
    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...
397
    {
398 39
        $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...
399 39
        $query_as_string = false;
400
        // ---------------------------------------------------------------------------------
401 39
        if ($whereInFile instanceof WhereInFile && $whereInFile->size()) {
402
            // $request = $this->prepareSelectWhereIn($request, $whereInFile);
403 1
            $structure = $whereInFile->fetchUrlParams();
404
            // $structure = [];
405 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...
406 1
            $query_as_string = true;
407
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
408
        // ---------------------------------------------------------------------------------
409
        // if result to file
410 39
        if ($writeToFile instanceof WriteToFile && $writeToFile->fetchFormat()) {
411 1
            $query->setFormat($writeToFile->fetchFormat());
412 1
            unset($urlParams['extremes']);
413
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
414
        // ---------------------------------------------------------------------------------
415
        // makeRequest read
416 39
        $request = $this->makeRequest($query, $urlParams, $query_as_string);
417
        // ---------------------------------------------------------------------------------
418
        // attach files
419 39
        if ($whereInFile instanceof WhereInFile && $whereInFile->size()) {
420 1
            $request->attachFiles($whereInFile->fetchFiles());
421
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
422
        // ---------------------------------------------------------------------------------
423
        // result to file
424 39
        if ($writeToFile instanceof WriteToFile && $writeToFile->fetchFormat()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
425
426 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...
427 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...
428
429 1
                $isGz = $writeToFile->getGzip();
430
431 1
                if ($isGz) {
432
                    // write gzip header
433
                    // "\x1f\x8b\x08\x00\x00\x00\x00\x00"
434
                    // fwrite($fout, "\x1F\x8B\x08\x08".pack("V", time())."\0\xFF", 10);
435
                    // write the original file name
436
                    // $oname = str_replace("\0", "", basename($writeToFile->fetchFile()));
437
                    // fwrite($fout, $oname."\0", 1+strlen($oname));
438
439
                    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...
440
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
441
                }
442
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
443
444
                $request->setResultFileHandle($fout, $isGz)->setCallbackFunction(function(CurlerRequest $request) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
introduced by
Closure not using "$this" should be declared static.
Loading history...
introduced by
Closure does not have void return type hint.
Loading history...
445
                    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...
446 1
                });
447
            }
448
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
449 39
        if ($this->xClickHouseProgress)
450
        {
451 1
            $request->setFunctionProgress([$this, '__findXClickHouseProgress']);
452
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
453
        // ---------------------------------------------------------------------------------
454 39
        return $request;
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 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...
459
    {
460 1
        $this->_query_degenerations = [];
461 1
        return true;
462
    }
463
464 67
    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...
465
    {
466 67
        $this->_query_degenerations[] = $degeneration;
467 67
        return true;
468
    }
469
470
    /**
471
     * @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...
472
     * @return CurlerRequest
473
     * @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...
474
     */
475 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...
476
    {
477 26
        $urlParams = ['readonly' => 0];
478 26
        return $this->makeRequest($query, $urlParams);
479
    }
480
481
    /**
482
     * @throws TransportException
0 ignored issues
show
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
483
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
484 37
    public function ping() : bool
485
    {
486 37
        $request = new CurlerRequest();
487 37
        $request->url($this->getUri())->verbose(false)->GET()->connectTimeOut($this->getConnectTimeOut());
488 37
        $this->_curler->execOne($request);
489
490 37
        return $request->response()->body() === 'Ok.' . PHP_EOL;
491
    }
492
493
    /**
494
     * @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...
495
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
496
     * @return Query
497
     */
498 45
    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...
499
    {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
500
501
        // add Degeneration query
502 45
        foreach ($this->_query_degenerations as $degeneration) {
503 45
            $degeneration->bindParams($bindings);
504
        }
505
506 45
        return new Query($sql, $this->_query_degenerations);
507
    }
508
509
510
    /**
511
     * @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...
512
     * @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...
513
     * @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...
514
     * @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...
515
     * @return CurlerRequest
516
     * @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...
517
     */
518 38
    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...
519
    {
520 38
        if ($sql instanceof Query) {
521
            return $this->getRequestWrite($sql);
522
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
523 38
        $query = $this->prepareQuery($sql, $bindings);
524 38
        $query->setFormat('JSON');
525 38
        return $this->getRequestRead($query, $whereInFile, $writeToFile);
526
    }
527
528
529
530
531
    /**
532
     * @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...
533
     * @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...
534
     * @return CurlerRequest
535
     * @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...
536
     */
537 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...
538
    {
539 27
        if ($sql instanceof Query) {
540
            return $this->getRequestWrite($sql);
541
        }
542
543 27
        $query = $this->prepareQuery($sql, $bindings);
544 26
        return $this->getRequestWrite($query);
545
    }
546
547
    /**
548
     * @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...
549
     * @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...
550
     */
551 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...
552
    {
553 10
        return $this->_curler->execLoopWait();
554
    }
555
556
    /**
557
     * @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...
558
     * @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...
559
     * @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...
560
     * @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...
561
     * @return Statement
562
     * @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...
563
     * @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...
564
     */
565 31
    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...
566
    {
567 31
        $request = $this->prepareSelect($sql, $bindings, $whereInFile, $writeToFile);
568 31
        $this->_curler->execOne($request);
569 31
        return new Statement($request);
570
    }
571
572
    /**
573
     * @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...
574
     * @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...
575
     * @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...
576
     * @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...
577
     * @return Statement
578
     * @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...
579
     * @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...
580
     */
581 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...
582
    {
583 7
        $request = $this->prepareSelect($sql, $bindings, $whereInFile, $writeToFile);
584 7
        $this->_curler->addQueLoop($request);
585 7
        return new Statement($request);
586
    }
587
588
    /**
589
     * @param callable $callback
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
590
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
591 1
    public function setProgressFunction(callable $callback)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::setProgressFunction() does not have void return type hint.
Loading history...
introduced by
Method \ClickHouseDB\Transport\Http::setProgressFunction() does not need documentation comment.
Loading history...
592
    {
593 1
        $this->xClickHouseProgress = $callback;
594 1
    }
595
596
    /**
597
     * @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...
598
     * @param mixed[] $bindings
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
599
     * @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...
600
     * @return Statement
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
    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...
604
    {
605 27
        $request = $this->prepareWrite($sql, $bindings);
606 26
        $this->_curler->execOne($request);
607 26
        $response = new Statement($request);
608 26
        if ($exception) {
609 26
            if ($response->isError()) {
610 3
                $response->error();
611
            }
612
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
613 24
        return $response;
614
    }
615
616
    /**
617
     * @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...
618
     * @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...
619
     * @return Statement
620
     * @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...
621
     */
622 2
    private function streaming(Stream $streamRW,CurlerRequest $request)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\Http::streaming() does not have return type hint for its return value but it should be possible to add it based on @return annotation "Statement".
Loading history...
Coding Style introduced by
Expected 1 space between comma and type hint "CurlerRequest"; 0 found
Loading history...
623
    {
624 2
        $callable=$streamRW->getClosure();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 1 space but found 0 spaces

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

To visualize

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

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

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

will produce no issues.

Loading history...
625 2
        $stream=$streamRW->getStream();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 0 spaces

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

To visualize

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

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

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

will produce no issues.

Loading history...
626
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 3 empty lines
Loading history...
627
628
629
        try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
630
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
631
632 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...
633
                if ($streamRW->isWrite())
634
                {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
635
636
                    $callable = function ($ch, $fd, $length) use ($stream) {
0 ignored issues
show
introduced by
Closure not using "$this" should be declared static.
Loading history...
637
                        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...
638
                    };
639
                } else {
640
                    $callable = function ($ch, $fd) use ($stream) {
0 ignored issues
show
introduced by
Closure not using "$this" should be declared static.
Loading history...
641
                        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...
642
                    };
643
                }
644
            }
645
646 2
            if ($streamRW->isGzipHeader()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
647
648 1
                if ($streamRW->isWrite())
649
                {
650 1
                    $request->header('Content-Encoding', 'gzip');
651 1
                    $request->header('Content-Type', 'application/x-www-form-urlencoded');
652
                } else {
653
                    $request->header('Accept-Encoding', 'gzip');
654
                }
0 ignored issues
show
Coding Style introduced by
Blank line found after control structure
Loading history...
655
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
656
            }
657
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 3 empty lines
Loading history...
658
659
660 2
            $request->header('Transfer-Encoding', 'chunked');
661
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
662
663 2
            if ($streamRW->isWrite())
664
            {
665 1
                $request->setReadFunction($callable);
666
            } else {
667 1
                $request->setWriteFunction($callable);
668
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 3 empty lines
Loading history...
669
670
671
//                $request->setHeaderFunction($callableHead);
672
            }
673
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
674
675 2
            $this->_curler->execOne($request,true);
676 2
            $response = new Statement($request);
677 2
            if ($response->isError()) {
678
                $response->error();
679
            }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
680 2
            return $response;
681
        } finally {
682 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...
683 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...
684
        }
685
686
687
    }
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...
688
689
690
    /**
691
     * @param Stream $streamRead
692
     * @param string $sql
693
     * @param mixed[] $bindings
694
     * @return Statement
695
     * @throws \ClickHouseDB\Exception\TransportException
0 ignored issues
show
introduced by
Class \ClickHouseDB\Exception\TransportException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
696
     */
697 1
    public function streamRead(Stream $streamRead,$sql,$bindings=[])
698
    {
699 1
        $sql=$this->prepareQuery($sql,$bindings);
700 1
        $request=$this->getRequestRead($sql);
701 1
        return $this->streaming($streamRead,$request);
702
703
    }
704
705
    /**
706
     * @param Stream $streamWrite
707
     * @param string $sql
708
     * @param mixed[] $bindings
709
     * @return Statement
710
     * @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...
711
     */
712 1
    public function streamWrite(Stream $streamWrite,$sql,$bindings=[])
713
    {
714 1
        $sql=$this->prepareQuery($sql,$bindings);
715 1
        $request = $this->writeStreamData($sql);
716 1
        return $this->streaming($streamWrite,$request);
717
    }
718
}
719