Failed Conditions
Push — master ( 3d6697...288e80 )
by Igor
02:40
created

CurlerRequest::id()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
0 ignored issues
show
introduced by
Missing declare(strict_types=1).
Loading history...
2
3
namespace ClickHouseDB\Transport;
4
5
use const CURLOPT_HTTPGET;
6
use const CURLOPT_POST;
7
8
class CurlerRequest
9
{
10
    /**
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...
11
     * @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...
12
     */
13
    public $extendinfo = array();
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
14
15
    /**
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...
16
     * @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...
17
     */
18
    private $parameters = '';
19
20
    /**
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...
21
     * @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...
22
     */
23
    private $options;
24
25
    /**
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...
26
     * @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...
27
     */
28
    private $headers; // Parsed reponse header object.
29
30
    /**
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...
31
     * @var string
32
     */
33
    private $url;
34
35
    /**
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...
36
     * @var string
37
     */
38
    private $method;
39
40
    /**
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...
41
     * @var bool
42
     */
43
    private $id;
44
45
    /**
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...
46
     * @var resource|null
47
     */
48
    private $handle;
49
50
    /** @var CurlerResponse */
51
    private $response;
52
53
    /** @var bool */
54
    private $_persistent = false;
55
56
    /**
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...
57
     * @var bool
58
     */
59
    private $_attachFiles = false;
60
61
    /**
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...
62
     * @var string
63
     */
64
    private $callback_class = '';
65
66
    /**
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...
67
     * @var string
68
     */
69
    private $callback_functionName = '';
70
71
    /**
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...
72
     * @var bool
73
     */
74
    private $_httpCompression = false;
75
76
    /**
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...
77
     * @var callable
78
     */
79
    private $callback_function = null;
80
81
    /**
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...
82
     * @var bool|resource
83
     */
84
    private $infile_handle = false;
85
86
    /**
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...
87
     * @var int
88
     */
89
    private $_dns_cache = 120;
90
91
    /**
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...
92
     * @var resource
93
     */
94
    private $resultFileHandle = null;
95
96
    /**
97
     * @param bool $id
98
     */
99 49
    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...
100
    {
101 49
        $this->id = $id;
102
103 49
        $this->header('Cache-Control', 'no-cache, no-store, must-revalidate');
104 49
        $this->header('Expires', '0');
105 49
        $this->header('Pragma', 'no-cache');
106
107 49
        $this->options = array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
108 49
            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...
109 49
            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...
110 49
            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...
111 49
            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...
112 49
            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...
113 49
            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...
114 49
            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...
115 49
            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...
116 49
            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...
117 49
            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...
118 49
            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...
119 49
            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...
120
        );
121 49
    }
122
123
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
124
     *
125
     */
126 48
    public function __destruct()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::__destruct() does not need documentation comment.
Loading history...
127
    {
128 48
        $this->close();
129 48
    }
130
131
132 48
    public function close()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::close() does not have void return type hint.
Loading history...
133
    {
134 48
        if ($this->handle)
135
        {
136 48
            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...
137
        }
138 48
        $this->handle = null;
139 48
    }
140
141
    /**
142
     * @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...
143
     */
144 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...
145
    {
146 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...
147
148 1
        $out = [];
149 1
        foreach ($attachFiles as $post_name => $file_path) {
150 1
            $out[$post_name] = new \CURLFile($file_path);
0 ignored issues
show
introduced by
Class \CURLFile should not be referenced via a fully qualified name, but via a use statement.
Loading history...
151
        }
152
153 1
        $this->_attachFiles = true;
154 1
        $this->parameters($out);
155 1
    }
156
157
158
    /**
159
     * @param bool $set
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
160
     * @return $this
161
     */
162
    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...
163
    {
164
        if ($set) {
165
            $this->id = $set;
166
        }
167
168
        return $this;
169
    }
170
171
    /**
172
     * @param array $params
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@param annotation of method \ClickHouseDB\Transport\CurlerRequest::setRequestExtendedInfo() does not specify type hint for items of its traversable parameter $params.
Loading history...
173
     * @return $this
174
     */
175 40
    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...
176
    {
177 40
        $this->extendinfo = $params;
178 40
        return $this;
179
    }
180
181
    /**
182
     * @param string|integer|null $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Expected "int" but found "integer" in @param annotation.
Loading history...
183
     * @return mixed
184
     */
185 40
    public function getRequestExtendedInfo($key = null)
186
    {
187 40
        if ($key) {
188 40
            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...
189
        }
190
191
        return $this->extendinfo;
192
    }
193
194
    /**
195
     * @return bool|resource
196
     */
197 8
    public function getInfileHandle()
198
    {
199 8
        return $this->infile_handle;
200
    }
201
202
    /**
203
     * @param string $file_name
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
204
     * @return bool|resource
205
     */
206 8
    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...
207
    {
208 8
        $this->header('Expect', '');
209 8
        $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...
210 8
        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...
211
        {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
212
213 8
            if ($this->_httpCompression) {
214 8
                $this->header('Content-Encoding', 'gzip');
215 8
                $this->header('Content-Type', 'application/x-www-form-urlencoded');
216
217 8
                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...
218
219 8
                $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...
220
            } else {
221
                $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...
222
            }
223
224 8
            $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...
225
        }
226
227 8
        return $this->infile_handle;
228
    }
229
230
    /**
231
     * @param callable $callback
232
     */
233 8
    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...
234
    {
235 8
        $this->callback_function = $callback;
236 8
    }
237
238
    /**
239
     * @param callable $callback
240
     */
241 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...
242
    {
243 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...
244 1
    }
245
    /**
246
     * @param callable $callback
247
     */
248 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...
249
    {
250 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...
251 3
    }
252
253
    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...
254
    {
255
        $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...
256
    }
257
258
    /**
259
     * @param string $classCallBack
260
     * @param string $functionName
261
     */
262
    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...
263
    {
264
        $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...
265
        $this->callback_functionName = $functionName;
266
    }
267
268
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
269
     *
270
     */
271 10
    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...
272
    {
273 10
        if ($this->callback_function) {
274 8
            $x = $this->callback_function;
275 8
            $x($this);
276
        }
277
278 10
        if ($this->callback_class && $this->callback_functionName) {
0 ignored issues
show
introduced by
Use early exit to reduce code nesting.
Loading history...
279
            $c = $this->callback_functionName;
280
            $this->callback_class->$c($this);
281
        }
282 10
    }
283
284
    /**
285
     * @param bool $result
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
286
     * @return string
287
     */
288
    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...
289
    {
290
        $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...
291
        $message .= 'URL:' . $this->url . "\n\n";
292
        $message .= 'METHOD:' . $this->method . "\n\n";
293
        $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...
294
        $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...
295
        $message .= "-----------------------------------\n";
296
297
        if ($result) {
298
            return $message;
299
        }
300
301
        echo $message;
302
        return '';
303
    }
304
305
    /**
306
     * @return bool
307
     */
308 13
    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...
309
    {
310 13
        return $this->id;
311
    }
312
313
    /**
314
     * @param integer $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Expected "int" but found "integer" in @param annotation.
Loading history...
315
     * @param mixed $value
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
316
     * @return $this
317
     */
318 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...
319
    {
320 1
        $this->options[$key] = $value;
321 1
        return $this;
322
    }
323
324
    /**
325
     * @return $this
326
     */
327 1
    public function persistent()
328
    {
329 1
        $this->_persistent = true;
330 1
        return $this;
331
    }
332
333
    /**
334
     * @return bool
335
     */
336 10
    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...
337
    {
338 10
        return $this->_persistent;
339
    }
340
341
    /**
342
     * @param int $sec
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
343
     * @return $this
344
     */
345
    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...
346
    {
347
        $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...
348
        $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...
349
        $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...
350
351
        return $this;
352
    }
353
354
    /**
355
     * @param bool $flag
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
356
     * @return $this
357
     */
358 49
    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...
359
    {
360 49
        $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...
361 49
        return $this;
362
    }
363
364
    /**
365
     * @param string $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
366
     * @param string $value
367
     * @return $this
368
     */
369 49
    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...
370
    {
371 49
        $this->headers[$key] = $value;
372 49
        return $this;
373
    }
374
375
    /**
376
     * @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...
377
     */
378
    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...
379
    {
380
        $head = [];
381
        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...
382
                    $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...
383
        }
384
        return $head;
385
    }
386
387
    /**
388
     * @param string $url
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
389
     * @return $this
390
     */
391 49
    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...
392
    {
393 49
        $this->url = $url;
394 49
        return $this;
395
    }
396
397
    /**
398
     * @return mixed
399
     */
400
    public function getUrl()
401
    {
402
        return $this->url;
403
    }
404
405
406
    /**
407
     * @param string $id
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
408
     * @return string
409
     */
410 13
    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...
411
    {
412 13
        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...
413
    }
414
415
    /**
416
     * @param bool $flag
417
     */
418 40
    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...
419
    {
420 40
        if ($flag) {
421 40
            $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...
422 40
            $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...
423
        } else
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after ELSE keyword; newline found
Loading history...
424
        {
425
            $this->_httpCompression = false;
426
            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...
427
        }
428 40
    }
429
430
    /**
431
     * @param string $username
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
432
     * @param string $password
433
     * @return $this
434
     */
435 40
    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...
436
    {
437 40
        $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...
438 40
        return $this;
439
    }
440
441
    /**
442
     * @param array|string $data
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
@param annotation of method \ClickHouseDB\Transport\CurlerRequest::parameters() does not specify type hint for items of its traversable parameter $data.
Loading history...
443
     * @return $this
444
     */
445 1
    public function parameters($data)
446
    {
447 1
        $this->parameters = $data;
448 1
        return $this;
449
    }
450
451
    /**
452
     * The number of seconds to wait when trying to connect. Use 0 for infinite waiting.
453
     *
454
     * @param int $seconds
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
455
     * @return $this
456
     */
457 49
    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...
458
    {
459 49
        $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...
460 49
        return $this;
461
    }
462
463
    /**
464
     * The maximum number of seconds (float) allowed to execute cURL functions.
465
     *
466
     * @param float $seconds
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
467
     * @return $this
468
     */
469 40
    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...
470
    {
471 40
        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...
472
    }
473
474
    /**
475
     * The maximum allowed number of milliseconds to perform cURL functions.
476
     *
477
     * @param int $ms millisecond
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
478
     * @return $this
479
     */
480 40
    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...
481
    {
482 40
        $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...
483 40
        return $this;
484
    }
485
486
487
    /**
488
     * @param array|mixed $data
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
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...
489
     * @return $this
490
     * @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...
491
     */
492 40
    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...
493
    {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
494
495 40
        $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...
496 40
        $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...
497
498 40
        if ($data === null) {
499
            $this->parameters = '{}';
500
            return $this;
501
        }
502
503 40
        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...
504 40
            $this->parameters = $data;
505 40
            return $this;
506
        }
507
508
        $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...
509
510
        if (!$this->parameters && $data) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
511
            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...
512
        }
513
514
        return $this;
515
    }
516
517
    /**
518
     * @return resource
519
     */
520
    public function getResultFileHandle()
521
    {
522
        return $this->resultFileHandle;
523
    }
524
525
    /**
526
     * @return bool
527
     */
528
    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...
529
    {
530
        return ($this->resultFileHandle ? true : false);
0 ignored issues
show
introduced by
Usage of language construct "return" with parentheses is disallowed.
Loading history...
531
    }
532
533
    /**
534
     * @param resource $h resource
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
535
     * @param bool $zlib
0 ignored issues
show
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
536
     * @return $this
537
     */
538 1
    public function setResultFileHandle($h, $zlib = false)
539
    {
540 1
        $this->resultFileHandle = $h;
541 1
        if ($zlib) {
542
            $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...
543
            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...
544
        }
545 1
        return $this;
546
    }
547
548
    /**
549
     * @return CurlerRequest
550
     */
551
    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...
552
    {
553
        return $this->execute('PUT');
554
    }
555
556
    /**
557
     * @return CurlerRequest
558
     */
559 40
    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...
560
    {
561 40
        return $this->execute('POST');
562
    }
563
564
    /**
565
     * @return CurlerRequest
566
     */
567
    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...
568
    {
569
        return $this->execute('OPTIONS');
570
    }
571
572
    /**
573
     * @return CurlerRequest
574
     */
575 39
    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...
576
    {
577 39
        return $this->execute('GET');
578
    }
579
580
    /**
581
     * The number of seconds that DNS records are stored in memory. By default this parameter is 120 (2 minutes).
582
     *
583
     * @param integer $set
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Expected "int" but found "integer" in @param annotation.
Loading history...
584
     * @return $this
585
     */
586
    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...
587
    {
588
        $this->_dns_cache = $set;
589
        return $this;
590
    }
591
592
    /**
593
     * The number of seconds that DNS records are stored in memory. By default this parameter is 120 (2 minutes).
594
     *
595
     * @return int
596
     */
597 48
    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...
598
    {
599 48
        return $this->_dns_cache;
600
    }
601
602
    /**
603
     * @param string $method
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
604
     * @return $this
605
     */
606 49
    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...
607
    {
608 49
        $this->method = $method;
609 49
        return $this;
610
    }
611
612
    /**
613
     * @return CurlerResponse
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
614
     * @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...
615
     */
616 48
    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...
617
    {
618 48
        if (! $this->response) {
619
            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...
620
        }
621
622 48
        return $this->response;
623
    }
624
625 29
    public function isResponseExists() : bool
626
    {
627 29
        return $this->response !== null;
628
    }
629
630 48
    public function setResponse(CurlerResponse $response) : void
631
    {
632 48
        $this->response = $response;
633 48
    }
634
635
    /**
636
     * @return mixed
637
     */
638 48
    public function handle()
639
    {
640 48
        $this->prepareRequest();
641 48
        return $this->handle;
642
    }
643
644
    /**
645
     * @param callable $callback
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setFunctionProgress() has useless @param annotation for parameter $callback.
Loading history...
646
     * @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...
647
     */
648 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...
649
    {
650 1
        if (!is_callable($callback)) {
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
Expected 1 space(s) after NOT operator; 0 found
Loading history...
651
            throw new \Exception('setFunctionProgress not is_callable');
0 ignored issues
show
introduced by
Class \Exception should not be referenced via a fully qualified name, but via a use statement.
Loading history...
652
        }
653
654 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...
655 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...
656 1
    }
657
658
659
    /**
660
     * @return bool
661
     */
662 48
    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...
663
    {
664 48
        if (!$this->handle) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
665 48
            $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...
666
        }
667
668 48
        $curl_opt = $this->options;
669 48
        $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...
670
671 48
        if ($this->_attachFiles) {
672 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...
673
        }
674
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
675
676 48
        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...
677 39
            $curl_opt[CURLOPT_HTTPGET]       = true;
678 39
            $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...
679 39
            $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...
680
        } else {
681 37
            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...
682 37
                $curl_opt[CURLOPT_POST] = true;
683
            }
684
685 37
            $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...
686
687 37
            if ($this->parameters) {
688 37
                $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...
689
690 37
                if (!is_array($this->parameters)) {
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...
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
691 37
                    $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...
692
                }
693
            }
694
        }
695
        // CURLOPT_DNS_CACHE_TIMEOUT - Количество секунд, в течение которых в памяти хранятся DNS-записи.
696 48
        $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...
697 48
        $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...
698
699 48
        if (!empty($this->headers) && sizeof($this->headers)) {
0 ignored issues
show
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...
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
700 48
            $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...
701
702 48
            foreach ($this->headers as $key => $value) {
703 48
                $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...
704
            }
705
        }
706
707 48
        if (!empty($curl_opt[CURLOPT_INFILE])) {
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...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
708
709 8
            $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...
710
        }
711
712 48
        if (!empty($curl_opt[CURLOPT_WRITEFUNCTION]))
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
Expected 1 space(s) after NOT operator; 0 found
Loading history...
713
        {
714 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...
715
        }
716
717 48
        if ($this->resultFileHandle) {
718 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...
719 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...
720
        }
721
722 48
        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...
723
            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...
724
        }
725 48
        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...
726 48
        return true;
727
    }
728
}
729