Failed Conditions
Pull Request — master (#102)
by Šimon
02:27
created

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