Completed
Push — master ( 4e5b03...242d64 )
by Igor
10s
created

CurlerRequest::GET()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
0 ignored issues
show
introduced by
Missing declare(strict_types = 1).
Loading history...
2
3
namespace ClickHouseDB\Transport;
4
5
class CurlerRequest
6
{
7
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$extendinfo with single line content, use one-line comment instead.
Loading history...
8
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Transport\CurlerRequest::$extendinfo does not specify type hint for its items.
Loading history...
9
     */
10
    public $extendinfo = array();
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
11
12
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$parameters with single line content, use one-line comment instead.
Loading history...
13
     * @var string|array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Transport\CurlerRequest::$parameters does not specify type hint for its items.
Loading history...
14
     */
15
    private $parameters = '';
16
17
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$options with single line content, use one-line comment instead.
Loading history...
18
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Transport\CurlerRequest::$options does not specify type hint for its items.
Loading history...
19
     */
20
    private $options;
21
22
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$headers with single line content, use one-line comment instead.
Loading history...
23
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Transport\CurlerRequest::$headers does not specify type hint for its items.
Loading history...
24
     */
25
    private $headers; // Parsed reponse header object.
26
27
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$url with single line content, use one-line comment instead.
Loading history...
28
     * @var string
29
     */
30
    private $url;
31
32
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$method with single line content, use one-line comment instead.
Loading history...
33
     * @var string
34
     */
35
    private $method;
36
37
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$id with single line content, use one-line comment instead.
Loading history...
38
     * @var bool
39
     */
40
    private $id;
41
42
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$handle with single line content, use one-line comment instead.
Loading history...
43
     * @var resource|null
44
     */
45
    private $handle;
46
47
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$resp with single line content, use one-line comment instead.
Loading history...
48
     * @var CurlerResponse
49
     */
50
    private $resp = null;
51
52
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$_persistent with single line content, use one-line comment instead.
Loading history...
53
     * @var bool
54
     */
55
    private $_persistent = false;
56
57
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$_attachFiles with single line content, use one-line comment instead.
Loading history...
58
     * @var bool
59
     */
60
    private $_attachFiles = false;
61
62
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$callback_class with single line content, use one-line comment instead.
Loading history...
63
     * @var string
64
     */
65
    private $callback_class = '';
66
67
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$callback_functionName with single line content, use one-line comment instead.
Loading history...
68
     * @var string
69
     */
70
    private $callback_functionName = '';
71
72
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$_httpCompression with single line content, use one-line comment instead.
Loading history...
73
     * @var bool
74
     */
75
    private $_httpCompression = false;
76
77
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$callback_function with single line content, use one-line comment instead.
Loading history...
78
     * @var callable
79
     */
80
    private $callback_function = null;
81
82
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$infile_handle with single line content, use one-line comment instead.
Loading history...
83
     * @var bool|resource
84
     */
85
    private $infile_handle = false;
86
87
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$_dns_cache with single line content, use one-line comment instead.
Loading history...
88
     * @var int
89
     */
90
    private $_dns_cache = 120;
91
92
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$resultFileHandle with single line content, use one-line comment instead.
Loading history...
93
     * @var resource
94
     */
95
    private $resultFileHandle = null;
96
97
    /**
98
     * @param bool $id
99
     */
100 43
    public function __construct($id = false)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::__construct() does not have parameter type hint for its parameter $id but it should be possible to add it based on @param annotation "bool".
Loading history...
101
    {
102 43
        $this->id = $id;
103
104 43
        $this->header('Cache-Control', 'no-cache, no-store, must-revalidate');
105 43
        $this->header('Expires', '0');
106 43
        $this->header('Pragma', 'no-cache');
107
108 43
        $this->options = array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
109 43
            CURLOPT_SSL_VERIFYHOST => 0,
0 ignored issues
show
introduced by
Constant CURLOPT_SSL_VERIFYHOST should not be referenced via a fallback global name, but via a use statement.
Loading history...
110 43
            CURLOPT_SSL_VERIFYPEER => false,
0 ignored issues
show
introduced by
Constant CURLOPT_SSL_VERIFYPEER should not be referenced via a fallback global name, but via a use statement.
Loading history...
111 43
            CURLOPT_TIMEOUT => 10,
0 ignored issues
show
introduced by
Constant CURLOPT_TIMEOUT should not be referenced via a fallback global name, but via a use statement.
Loading history...
112 43
            CURLOPT_CONNECTTIMEOUT => 5, // Количество секунд ожидания при попытке соединения
0 ignored issues
show
introduced by
Constant CURLOPT_CONNECTTIMEOUT should not be referenced via a fallback global name, but via a use statement.
Loading history...
113 43
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
0 ignored issues
show
introduced by
Constant CURLOPT_HTTP_VERSION should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Constant CURL_HTTP_VERSION_1_1 should not be referenced via a fallback global name, but via a use statement.
Loading history...
114 43
            CURLOPT_MAXREDIRS => 10,
0 ignored issues
show
introduced by
Constant CURLOPT_MAXREDIRS should not be referenced via a fallback global name, but via a use statement.
Loading history...
115 43
            CURLOPT_HEADER => TRUE,
0 ignored issues
show
introduced by
Constant CURLOPT_HEADER should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected true, but found TRUE.
Loading history...
116 43
            CURLOPT_FOLLOWLOCATION => TRUE,
0 ignored issues
show
introduced by
Constant CURLOPT_FOLLOWLOCATION should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected true, but found TRUE.
Loading history...
117 43
            CURLOPT_AUTOREFERER => 1, // при редиректе подставлять в «Referer:» значение из «Location:»
0 ignored issues
show
introduced by
Constant CURLOPT_AUTOREFERER should not be referenced via a fallback global name, but via a use statement.
Loading history...
118 43
            CURLOPT_BINARYTRANSFER => 1, // передавать в binary-safe
0 ignored issues
show
introduced by
Constant CURLOPT_BINARYTRANSFER should not be referenced via a fallback global name, but via a use statement.
Loading history...
119 43
            CURLOPT_RETURNTRANSFER => TRUE,
0 ignored issues
show
introduced by
Constant CURLOPT_RETURNTRANSFER should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected true, but found TRUE.
Loading history...
120 43
            CURLOPT_USERAGENT => 'smi2/PHPClickHouse/client',
0 ignored issues
show
introduced by
Constant CURLOPT_USERAGENT should not be referenced via a fallback global name, but via a use statement.
Loading history...
121
        );
122 43
    }
123
124
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
125
     *
126
     */
127 42
    public function __destruct()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::__destruct() does not need documentation comment.
Loading history...
128
    {
129 42
        $this->close();
130 42
    }
131
132
133 42
    public function close()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::close() does not have void return type hint.
Loading history...
134
    {
135 42
        if ($this->handle)
136
        {
137 42
            curl_close($this->handle);
0 ignored issues
show
introduced by
Function curl_close() should not be referenced via a fallback global name, but via a use statement.
Loading history...
138
        }
139 42
        $this->handle = null;
140 42
    }
141
142
    /**
143
     * @param array $attachFiles
0 ignored issues
show
introduced by
@param annotation of method \ClickHouseDB\Transport\CurlerRequest::attachFiles() does not specify type hint for items of its traversable parameter $attachFiles.
Loading history...
144
     */
145 1
    public function attachFiles($attachFiles)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::attachFiles() does not have parameter type hint for its parameter $attachFiles but it should be possible to add it based on @param annotation "array".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::attachFiles() does not have void return type hint.
Loading history...
146
    {
147 1
        $this->header("Content-Type", "multipart/form-data");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Content-Type does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal multipart/form-data does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
148
149 1
        $out = [];
150 1
        foreach ($attachFiles as $post_name => $file_path) {
151 1
            $out[$post_name] = new \CURLFile($file_path);
152
        }
153
154 1
        $this->_attachFiles = true;
155 1
        $this->parameters($out);
156 1
    }
157
158
159
    /**
160
     * @param bool $set
161
     * @return $this
162
     */
163
    public function id($set = false)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::id() does not have parameter type hint for its parameter $set but it should be possible to add it based on @param annotation "bool".
Loading history...
164
    {
165
        if ($set) {
166
            $this->id = $set;
167
        }
168
169
        return $this;
170
    }
171
172
    /**
173
     * @param array $params
0 ignored issues
show
introduced by
@param annotation of method \ClickHouseDB\Transport\CurlerRequest::setRequestExtendedInfo() does not specify type hint for items of its traversable parameter $params.
Loading history...
174
     * @return $this
175
     */
176 35
    public function setRequestExtendedInfo($params)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setRequestExtendedInfo() 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...
177
    {
178 35
        $this->extendinfo = $params;
179 35
        return $this;
180
    }
181
182
    /**
183
     * @param string|integer|null $key
0 ignored issues
show
introduced by
Expected "int" but found "integer" in @param annotation.
Loading history...
184
     * @return mixed
185
     */
186 35
    public function getRequestExtendedInfo($key = null)
187
    {
188 35
        if ($key) {
189 35
            return isset($this->extendinfo[$key]) ? $this->extendinfo[$key] : false;
0 ignored issues
show
introduced by
Use null coalesce operator instead of ternary operator.
Loading history...
190
        }
191
192
        return $this->extendinfo;
193
    }
194
195
    /**
196
     * @return bool|resource
197
     */
198 7
    public function getInfileHandle()
199
    {
200 7
        return $this->infile_handle;
201
    }
202
203
    /**
204
     * @param string $file_name
205
     * @return bool|resource
206
     */
207 7
    public function setInfile($file_name)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setInfile() 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...
208
    {
209 7
        $this->header('Expect', '');
210 7
        $this->infile_handle = fopen($file_name, 'r');
0 ignored issues
show
introduced by
Function fopen() should not be referenced via a fallback global name, but via a use statement.
Loading history...
211 7
        if (is_resource($this->infile_handle))
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...
212
        {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
213
214 7
            if ($this->_httpCompression) {
215 7
                $this->header('Content-Encoding', 'gzip');
216 7
                $this->header('Content-Type', 'application/x-www-form-urlencoded');
217
218 7
                stream_filter_append($this->infile_handle, 'zlib.deflate', STREAM_FILTER_READ, ["window" => 30]);
0 ignored issues
show
introduced by
Function stream_filter_append() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Constant STREAM_FILTER_READ should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style Comprehensibility introduced by
The string literal window does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
219
220 7
                $this->options[CURLOPT_SAFE_UPLOAD] = 1;
0 ignored issues
show
introduced by
Constant CURLOPT_SAFE_UPLOAD should not be referenced via a fallback global name, but via a use statement.
Loading history...
221
            } else {
222
                $this->options[CURLOPT_INFILESIZE] = filesize($file_name);
0 ignored issues
show
introduced by
Constant CURLOPT_INFILESIZE should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Function filesize() should not be referenced via a fallback global name, but via a use statement.
Loading history...
223
            }
224
225 7
            $this->options[CURLOPT_INFILE] = $this->infile_handle;
0 ignored issues
show
introduced by
Constant CURLOPT_INFILE should not be referenced via a fallback global name, but via a use statement.
Loading history...
226
        }
227
228 7
        return $this->infile_handle;
229
    }
230
231
    /**
232
     * @param callable $callback
233
     */
234 7
    public function setCallbackFunction($callback)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setCallbackFunction() does not have parameter type hint for its parameter $callback but it should be possible to add it based on @param annotation "callable".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setCallbackFunction() does not have void return type hint.
Loading history...
235
    {
236 7
        $this->callback_function = $callback;
237 7
    }
238
239
    /**
240
     * @param callable $callback
241
     */
242 1
    public function setWriteFunction($callback)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setWriteFunction() does not have parameter type hint for its parameter $callback but it should be possible to add it based on @param annotation "callable".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setWriteFunction() does not have void return type hint.
Loading history...
243
    {
244 1
        $this->options[CURLOPT_WRITEFUNCTION]=$callback;
0 ignored issues
show
introduced by
Constant CURLOPT_WRITEFUNCTION should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
245 1
    }
246
    /**
247
     * @param callable $callback
248
     */
249 3
    public function setReadFunction($callback)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setReadFunction() does not have parameter type hint for its parameter $callback but it should be possible to add it based on @param annotation "callable".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setReadFunction() does not have void return type hint.
Loading history...
250
    {
251 3
        $this->options[CURLOPT_READFUNCTION] = $callback;
0 ignored issues
show
introduced by
Constant CURLOPT_READFUNCTION should not be referenced via a fallback global name, but via a use statement.
Loading history...
252 3
    }
253
254
    public function setHeaderFunction($callback)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setHeaderFunction() does not have parameter type hint nor @param annotation for its parameter $callback.
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setHeaderFunction() does not have void return type hint.
Loading history...
255
    {
256
        $this->options[CURLOPT_HEADERFUNCTION] = $callback;
0 ignored issues
show
introduced by
Constant CURLOPT_HEADERFUNCTION should not be referenced via a fallback global name, but via a use statement.
Loading history...
257
    }
258
259
    /**
260
     * @param string $classCallBack
261
     * @param string $functionName
262
     */
263
    public function setCallback($classCallBack, $functionName)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setCallback() does not have parameter type hint for its parameter $classCallBack but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setCallback() does not have parameter type hint for its parameter $functionName but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setCallback() does not have void return type hint.
Loading history...
264
    {
265
        $this->callback_class = $classCallBack;
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
        $this->callback_functionName = $functionName;
267
    }
268
269
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
270
     *
271
     */
272 9
    public function onCallback()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::onCallback() does not have void return type hint.
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::onCallback() does not need documentation comment.
Loading history...
273
    {
274 9
        if ($this->callback_function) {
275 7
            $x = $this->callback_function;
276 7
            $x($this);
277
        }
278
279 9
        if ($this->callback_class && $this->callback_functionName) {
0 ignored issues
show
introduced by
Use early exit to reduce code nesting.
Loading history...
280
            $c = $this->callback_functionName;
281
            $this->callback_class->$c($this);
282
        }
283 9
    }
284
285
    /**
286
     * @param bool $result
287
     * @return string
288
     */
289
    public function dump($result = false)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::dump() does not have parameter type hint for its parameter $result but it should be possible to add it based on @param annotation "bool".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::dump() 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...
290
    {
291
        $message = "\n------------  Request ------------\n";
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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...
292
        $message .= 'URL:' . $this->url . "\n\n";
293
        $message .= 'METHOD:' . $this->method . "\n\n";
294
        $message .= 'PARAMS:' . print_r($this->parameters, true) . "\n";
0 ignored issues
show
introduced by
Function print_r() should not be referenced via a fallback global name, but via a use statement.
Loading history...
295
        $message .= 'PARAMS:' . print_r($this->headers, true) . "\n";
0 ignored issues
show
introduced by
Function print_r() should not be referenced via a fallback global name, but via a use statement.
Loading history...
296
        $message .= "-----------------------------------\n";
297
298
        if ($result) {
299
            return $message;
300
        }
301
302
        echo $message;
303
        return '';
304
    }
305
306
    /**
307
     * @return bool
308
     */
309 12
    public function getId()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::getId() 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...
310
    {
311 12
        return $this->id;
312
    }
313
314
    /**
315
     * @param integer $key
0 ignored issues
show
introduced by
Expected "int" but found "integer" in @param annotation.
Loading history...
316
     * @param mixed $value
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
317
     * @return $this
318
     */
319 1
    private function option($key, $value)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::option() does not have parameter type hint for its parameter $key but it should be possible to add it based on @param annotation "integer".
Loading history...
320
    {
321 1
        $this->options[$key] = $value;
322 1
        return $this;
323
    }
324
325
    /**
326
     * @return $this
327
     */
328 1
    public function persistent()
329
    {
330 1
        $this->_persistent = true;
331 1
        return $this;
332
    }
333
334
    /**
335
     * @return bool
336
     */
337 9
    public function isPersistent()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::isPersistent() 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...
338
    {
339 9
        return $this->_persistent;
340
    }
341
342
    /**
343
     * @param int $sec
344
     * @return $this
345
     */
346 35
    public function keepAlive($sec = 60)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::keepAlive() does not have parameter type hint for its parameter $sec but it should be possible to add it based on @param annotation "int".
Loading history...
347
    {
348 35
        $this->options[CURLOPT_FORBID_REUSE] = TRUE;
0 ignored issues
show
introduced by
Constant CURLOPT_FORBID_REUSE should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected true, but found TRUE.
Loading history...
349 35
        $this->headers['Connection'] = 'Keep-Alive';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
350 35
        $this->headers['Keep-Alive'] = $sec;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
351
352 35
        return $this;
353
    }
354
355
    /**
356
     * @param bool $flag
357
     * @return $this
358
     */
359 43
    public function verbose($flag = true)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::verbose() does not have parameter type hint for its parameter $flag but it should be possible to add it based on @param annotation "bool".
Loading history...
360
    {
361 43
        $this->options[CURLOPT_VERBOSE] = $flag;
0 ignored issues
show
introduced by
Constant CURLOPT_VERBOSE should not be referenced via a fallback global name, but via a use statement.
Loading history...
362 43
        return $this;
363
    }
364
365
    /**
366
     * @param string $key
367
     * @param string $value
368
     * @return $this
369
     */
370 43
    public function header($key, $value)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::header() does not have parameter type hint for its parameter $key but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::header() does not have parameter type hint for its parameter $value but it should be possible to add it based on @param annotation "string".
Loading history...
371
    {
372 43
        $this->headers[$key] = $value;
373 43
        return $this;
374
    }
375
376
    /**
377
     * @return array
0 ignored issues
show
introduced by
@return annotation of method \ClickHouseDB\Transport\CurlerRequest::getHeaders() does not specify type hint for items of its traversable return value.
Loading history...
378
     */
379
    public function getHeaders()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::getHeaders() does not have return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
380
    {
381
        $head = [];
382
        foreach ($this->headers as $key=>$value) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space before "=>"; 0 found
Loading history...
Coding Style introduced by
Expected 1 space after "=>"; 0 found
Loading history...
383
                    $head[] = sprintf("%s: %s", $key, $value);
0 ignored issues
show
introduced by
Function sprintf() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style Comprehensibility introduced by
The string literal %s: %s does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
384
        }
385
        return $head;
386
    }
387
388
    /**
389
     * @param string $url
390
     * @return $this
391
     */
392 43
    public function url($url)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::url() does not have parameter type hint for its parameter $url but it should be possible to add it based on @param annotation "string".
Loading history...
393
    {
394 43
        $this->url = $url;
395 43
        return $this;
396
    }
397
398
    /**
399
     * @return mixed
400
     */
401
    public function getUrl()
402
    {
403
        return $this->url;
404
    }
405
406
407
    /**
408
     * @param string $id
409
     * @return string
410
     */
411 12
    public function getUniqHash($id)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::getUniqHash() does not have parameter type hint for its parameter $id but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::getUniqHash() 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...
412
    {
413 12
        return $id . '.' . microtime() . mt_rand(0, 1000000);
0 ignored issues
show
introduced by
Function microtime() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Function mt_rand() should not be referenced via a fallback global name, but via a use statement.
Loading history...
414
    }
415
416
    /**
417
     * @param bool $flag
418
     */
419 35
    public function httpCompression($flag)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::httpCompression() does not have parameter type hint for its parameter $flag but it should be possible to add it based on @param annotation "bool".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::httpCompression() does not have void return type hint.
Loading history...
420
    {
421 35
        if ($flag) {
422 35
            $this->_httpCompression = $flag;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 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...
423 35
            $this->options[CURLOPT_ENCODING] = 'gzip';
0 ignored issues
show
introduced by
Constant CURLOPT_ENCODING should not be referenced via a fallback global name, but via a use statement.
Loading history...
424
        } else
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after ELSE keyword; newline found
Loading history...
425
        {
426
            $this->_httpCompression = false;
427
            unset($this->options[CURLOPT_ENCODING]);
0 ignored issues
show
introduced by
Constant CURLOPT_ENCODING should not be referenced via a fallback global name, but via a use statement.
Loading history...
428
        }
429 35
    }
430
431
    /**
432
     * @param string $username
433
     * @param string $password
434
     * @return $this
435
     */
436 35
    public function auth($username, $password)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::auth() 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\CurlerRequest::auth() 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...
437
    {
438 35
        $this->options[CURLOPT_USERPWD] = sprintf("%s:%s", $username, $password);
0 ignored issues
show
introduced by
Constant CURLOPT_USERPWD should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Function sprintf() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style Comprehensibility introduced by
The string literal %s:%s does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
439 35
        return $this;
440
    }
441
442
    /**
443
     * @param array|string $data
0 ignored issues
show
introduced by
@param annotation of method \ClickHouseDB\Transport\CurlerRequest::parameters() does not specify type hint for items of its traversable parameter $data.
Loading history...
444
     * @return $this
445
     */
446 1
    public function parameters($data)
447
    {
448 1
        $this->parameters = $data;
449 1
        return $this;
450
    }
451
452
    /**
453
     * The number of seconds to wait when trying to connect. Use 0 for infinite waiting.
454
     *
455
     * @param int $seconds
456
     * @return $this
457
     */
458 43
    public function connectTimeOut($seconds = 1)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::connectTimeOut() does not have parameter type hint for its parameter $seconds but it should be possible to add it based on @param annotation "int".
Loading history...
459
    {
460 43
        $this->options[CURLOPT_CONNECTTIMEOUT] = $seconds;
0 ignored issues
show
introduced by
Constant CURLOPT_CONNECTTIMEOUT should not be referenced via a fallback global name, but via a use statement.
Loading history...
461 43
        return $this;
462
    }
463
464
    /**
465
     * The maximum number of seconds (float) allowed to execute cURL functions.
466
     *
467
     * @param float $seconds
468
     * @return $this
469
     */
470 35
    public function timeOut($seconds = 10)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::timeOut() does not have parameter type hint for its parameter $seconds but it should be possible to add it based on @param annotation "float".
Loading history...
471
    {
472 35
        return $this->timeOutMs(intval($seconds * 1000));
0 ignored issues
show
introduced by
Function intval() should not be referenced via a fallback global name, but via a use statement.
Loading history...
473
    }
474
475
    /**
476
     * The maximum allowed number of milliseconds to perform cURL functions.
477
     *
478
     * @param int $ms millisecond
479
     * @return $this
480
     */
481 35
    protected function timeOutMs($ms = 10000)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::timeOutMs() does not have parameter type hint for its parameter $ms but it should be possible to add it based on @param annotation "int".
Loading history...
482
    {
483 35
        $this->options[CURLOPT_TIMEOUT_MS] = $ms;
0 ignored issues
show
introduced by
Constant CURLOPT_TIMEOUT_MS should not be referenced via a fallback global name, but via a use statement.
Loading history...
484 35
        return $this;
485
    }
486
487
488
    /**
489
     * @param array|mixed $data
0 ignored issues
show
introduced by
@param annotation of method \ClickHouseDB\Transport\CurlerRequest::parameters_json() does not specify type hint for items of its traversable parameter $data.
Loading history...
490
     * @return $this
491
     * @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...
492
     */
493 35
    public function parameters_json($data)
0 ignored issues
show
Coding Style introduced by
Method name "CurlerRequest::parameters_json" is not in camel caps format
Loading history...
494
    {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
495
496 35
        $this->header("Content-Type", "application/json, text/javascript; charset=utf-8");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Content-Type does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal application/json, text/javascript; charset=utf-8 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
497 35
        $this->header("Accept", "application/json, text/javascript, */*; q=0.01");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Accept does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal application/json, text/javascript, */*; q=0.01 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
498
499 35
        if ($data === null) {
500
            $this->parameters = '{}';
501
            return $this;
502
        }
503
504 35
        if (is_string($data)) {
0 ignored issues
show
introduced by
Function is_string() should not be referenced via a fallback global name, but via a use statement.
Loading history...
505 35
            $this->parameters = $data;
506 35
            return $this;
507
        }
508
509
        $this->parameters = json_encode($data);
0 ignored issues
show
introduced by
Function json_encode() should not be referenced via a fallback global name, but via a use statement.
Loading history...
510
511
        if (!$this->parameters && $data) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
512
            throw new \ClickHouseDB\Exception\TransportException('Cant json_encode: ' . strval($data));
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...
introduced by
Function strval() should not be referenced via a fallback global name, but via a use statement.
Loading history...
513
        }
514
515
        return $this;
516
    }
517
518
    /**
519
     * @return resource
520
     */
521
    public function getResultFileHandle()
522
    {
523
        return $this->resultFileHandle;
524
    }
525
526
    /**
527
     * @return bool
528
     */
529
    public function isResultFile()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::isResultFile() 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...
530
    {
531
        return ($this->resultFileHandle ? true : false);
0 ignored issues
show
introduced by
Usage of language construct "return" with parentheses is disallowed.
Loading history...
532
    }
533
534
    /**
535
     * @param resource $h resource
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
536
     * @param bool $zlib
0 ignored issues
show
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
537
     * @return $this
538
     */
539 1
    public function setResultFileHandle($h, $zlib = false)
540
    {
541 1
        $this->resultFileHandle = $h;
542 1
        if ($zlib) {
543
            $params = array('level' => 6, 'window' => 15, 'memory' => 9);
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
544
            stream_filter_append($this->resultFileHandle, 'zlib.deflate', STREAM_FILTER_WRITE, $params);
0 ignored issues
show
introduced by
Function stream_filter_append() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Constant STREAM_FILTER_WRITE should not be referenced via a fallback global name, but via a use statement.
Loading history...
545
        }
546 1
        return $this;
547
    }
548
549
    /**
550
     * @return CurlerRequest
551
     */
552
    public function PUT()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::PUT() 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...
553
    {
554
        return $this->execute('PUT');
555
    }
556
557
    /**
558
     * @return CurlerRequest
559
     */
560 35
    public function POST()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::POST() 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...
561
    {
562 35
        return $this->execute('POST');
563
    }
564
565
    /**
566
     * @return CurlerRequest
567
     */
568
    public function OPTIONS()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::OPTIONS() 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...
569
    {
570
        return $this->execute('OPTIONS');
571
    }
572
573
    /**
574
     * @return CurlerRequest
575
     */
576 36
    public function GET()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::GET() 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...
577
    {
578 36
        return $this->execute('GET');
579
    }
580
581
    /**
582
     * The number of seconds that DNS records are stored in memory. By default this parameter is 120 (2 minutes).
583
     *
584
     * @param integer $set
0 ignored issues
show
introduced by
Expected "int" but found "integer" in @param annotation.
Loading history...
585
     * @return $this
586
     */
587
    public function setDnsCache($set)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setDnsCache() does not have parameter type hint for its parameter $set but it should be possible to add it based on @param annotation "integer".
Loading history...
588
    {
589
        $this->_dns_cache = $set;
590
        return $this;
591
    }
592
593
    /**
594
     * The number of seconds that DNS records are stored in memory. By default this parameter is 120 (2 minutes).
595
     *
596
     * @return int
597
     */
598 42
    public function getDnsCache()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::getDnsCache() 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...
599
    {
600 42
        return $this->_dns_cache;
601
    }
602
603
    /**
604
     * @param string $method
605
     * @return $this
606
     */
607 43
    private function execute($method)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::execute() does not have parameter type hint for its parameter $method but it should be possible to add it based on @param annotation "string".
Loading history...
608
    {
609 43
        $this->method = $method;
610 43
        return $this;
611
    }
612
613
    /**
614
     * @return CurlerResponse
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...
616
     */
617 42
    public function response()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::response() does not have return type hint for its return value but it should be possible to add it based on @return annotation "CurlerResponse".
Loading history...
618
    {
619 42
        if (!$this->resp) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
620
            throw new \ClickHouseDB\Exception\TransportException('Can`t fetch response - is empty');
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...
621
        }
622
623 42
        return $this->resp;
624
    }
625
626
    /**
627
     * @return bool
628
     */
629 24
    public function isResponseExists()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::isResponseExists() 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...
630
    {
631 24
        return ($this->resp ? true : false);
0 ignored issues
show
introduced by
Usage of language construct "return" with parentheses is disallowed.
Loading history...
632
    }
633
634 42
    public function setResponse(CurlerResponse $response)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setResponse() does not have void return type hint.
Loading history...
635
    {
636 42
        $this->resp = $response;
637 42
    }
638
639
    /**
640
     * @return mixed
641
     */
642 42
    public function handle()
643
    {
644 42
        $this->prepareRequest();
645 42
        return $this->handle;
646
    }
647
648
    /**
649
     * @param callable $callback
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setFunctionProgress() has useless @param annotation for parameter $callback.
Loading history...
650
     * @throws \Exception
651
     */
652 1
    public function setFunctionProgress(callable $callback)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setFunctionProgress() does not have void return type hint.
Loading history...
653
    {
654 1
        if (!is_callable($callback)) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
introduced by
Function is_callable() should not be referenced via a fallback global name, but via a use statement.
Loading history...
655
            throw new \Exception('setFunctionProgress not is_callable');
656
        }
657
658 1
        $this->option(CURLOPT_NOPROGRESS, false);
0 ignored issues
show
introduced by
Constant CURLOPT_NOPROGRESS should not be referenced via a fallback global name, but via a use statement.
Loading history...
659 1
        $this->option(CURLOPT_PROGRESSFUNCTION, $callback); // version 5.5.0
0 ignored issues
show
introduced by
Constant CURLOPT_PROGRESSFUNCTION should not be referenced via a fallback global name, but via a use statement.
Loading history...
660 1
    }
661
662
663
    /**
664
     * @return bool
665
     */
666 42
    private function prepareRequest()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::prepareRequest() 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...
667
    {
668 42
        if (!$this->handle) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
669 42
            $this->handle = curl_init();
0 ignored issues
show
introduced by
Function curl_init() should not be referenced via a fallback global name, but via a use statement.
Loading history...
670
        }
671
672 42
        $curl_opt = $this->options;
673 42
        $method = $this->method;
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...
674
675 42
        if ($this->_attachFiles) {
676 1
            $curl_opt[CURLOPT_SAFE_UPLOAD] = true;
0 ignored issues
show
introduced by
Constant CURLOPT_SAFE_UPLOAD should not be referenced via a fallback global name, but via a use statement.
Loading history...
677
        }
678
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
679
680 42
        if (strtoupper($method) == 'GET') {
0 ignored issues
show
introduced by
Function strtoupper() should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Operator == is disallowed, use === instead.
Loading history...
681 36
            $curl_opt[CURLOPT_HTTPGET] = TRUE;
0 ignored issues
show
introduced by
Constant CURLOPT_HTTPGET should not be referenced via a fallback global name, but via a use statement.
Loading history...
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...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected true, but found TRUE.
Loading history...
682 36
            $curl_opt[CURLOPT_CUSTOMREQUEST] = strtoupper($method);
0 ignored issues
show
introduced by
Constant CURLOPT_CUSTOMREQUEST should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Function strtoupper() should not be referenced via a fallback global name, but via a use statement.
Loading history...
683 36
            $curl_opt[CURLOPT_POSTFIELDS] = false;
0 ignored issues
show
introduced by
Constant CURLOPT_POSTFIELDS should not be referenced via a fallback global name, but via a use statement.
Loading history...
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...
684
        } else {
685 32
            if (strtoupper($method) === 'POST') {
0 ignored issues
show
introduced by
Function strtoupper() should not be referenced via a fallback global name, but via a use statement.
Loading history...
686 32
                $curl_opt[CURLOPT_POST] = TRUE;
0 ignored issues
show
introduced by
Constant CURLOPT_POST should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected true, but found TRUE.
Loading history...
687
            }
688
689 32
            $curl_opt[CURLOPT_CUSTOMREQUEST] = strtoupper($method);
0 ignored issues
show
introduced by
Constant CURLOPT_CUSTOMREQUEST should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Function strtoupper() should not be referenced via a fallback global name, but via a use statement.
Loading history...
690
691 32
            if ($this->parameters) {
692 32
                $curl_opt[CURLOPT_POSTFIELDS] = $this->parameters;
0 ignored issues
show
introduced by
Constant CURLOPT_POSTFIELDS should not be referenced via a fallback global name, but via a use statement.
Loading history...
693
694 32
                if (!is_array($this->parameters)) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
introduced by
Function is_array() should not be referenced via a fallback global name, but via a use statement.
Loading history...
695 32
                    $this->header('Content-Length', strlen($this->parameters));
0 ignored issues
show
introduced by
Function strlen() should not be referenced via a fallback global name, but via a use statement.
Loading history...
696
                }
697
            }
698
        }
699
        // CURLOPT_DNS_CACHE_TIMEOUT - Количество секунд, в течение которых в памяти хранятся DNS-записи.
700 42
        $curl_opt[CURLOPT_DNS_CACHE_TIMEOUT] = $this->getDnsCache();
0 ignored issues
show
introduced by
Constant CURLOPT_DNS_CACHE_TIMEOUT should not be referenced via a fallback global name, but via a use statement.
Loading history...
701 42
        $curl_opt[CURLOPT_URL] = $this->url;
0 ignored issues
show
introduced by
Constant CURLOPT_URL should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 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...
702
703 42
        if (!empty($this->headers) && sizeof($this->headers)) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
introduced by
Function 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...
704 42
            $curl_opt[CURLOPT_HTTPHEADER] = array();
0 ignored issues
show
introduced by
Constant CURLOPT_HTTPHEADER should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
705
706 42
            foreach ($this->headers as $key => $value) {
707 42
                $curl_opt[CURLOPT_HTTPHEADER][] = sprintf("%s: %s", $key, $value);
0 ignored issues
show
introduced by
Constant CURLOPT_HTTPHEADER should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Function sprintf() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style Comprehensibility introduced by
The string literal %s: %s does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
708
            }
709
        }
710
711 42
        if (!empty($curl_opt[CURLOPT_INFILE])) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
introduced by
Constant CURLOPT_INFILE 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...
712
713 7
            $curl_opt[CURLOPT_PUT] = true;
0 ignored issues
show
introduced by
Constant CURLOPT_PUT should not be referenced via a fallback global name, but via a use statement.
Loading history...
714
        }
715
716 42
        if (!empty($curl_opt[CURLOPT_WRITEFUNCTION]))
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
introduced by
Constant CURLOPT_WRITEFUNCTION should not be referenced via a fallback global name, but via a use statement.
Loading history...
717
        {
718 1
            $curl_opt[CURLOPT_HEADER]=false;
0 ignored issues
show
introduced by
Constant CURLOPT_HEADER should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
719
        }
720
721 42
        if ($this->resultFileHandle) {
722 1
            $curl_opt[CURLOPT_FILE] = $this->resultFileHandle;
0 ignored issues
show
introduced by
Constant CURLOPT_FILE should not be referenced via a fallback global name, but via a use statement.
Loading history...
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...
723 1
            $curl_opt[CURLOPT_HEADER] = false;
0 ignored issues
show
introduced by
Constant CURLOPT_HEADER should not be referenced via a fallback global name, but via a use statement.
Loading history...
724
        }
725
726 42
        if ($this->options[CURLOPT_VERBOSE]) {
0 ignored issues
show
introduced by
Constant CURLOPT_VERBOSE should not be referenced via a fallback global name, but via a use statement.
Loading history...
727
            echo "\n-----------BODY REQUEST----------\n" . $curl_opt[CURLOPT_POSTFIELDS] . "\n------END--------\n";
0 ignored issues
show
introduced by
Constant CURLOPT_POSTFIELDS should not be referenced via a fallback global name, but via a use statement.
Loading history...
728
        }
729 42
        curl_setopt_array($this->handle, $curl_opt);
0 ignored issues
show
introduced by
Function curl_setopt_array() should not be referenced via a fallback global name, but via a use statement.
Loading history...
730 42
        return true;
731
    }
732
}
733