Failed Conditions
Pull Request — master (#102)
by Šimon
04:10
created

CurlerRequest   F

Complexity

Total Complexity 83

Size/Duplication

Total Lines 703
Duplicated Lines 0 %

Test Coverage

Coverage 76.15%

Importance

Changes 0
Metric Value
wmc 83
eloc 199
dl 0
loc 703
ccs 182
cts 239
cp 0.7615
rs 2
c 0
b 0
f 0

49 Methods

Rating   Name   Duplication   Size   Complexity  
A __destruct() 0 3 1
A getInfileHandle() 0 3 1
A setRequestExtendedInfo() 0 4 1
A keepAlive() 0 7 1
A close() 0 7 2
A getUniqHash() 0 3 1
A setReadFunction() 0 3 1
A isPersistent() 0 3 1
A dump() 0 15 2
A setInfile() 0 22 3
A url() 0 4 1
A id() 0 7 2
A getId() 0 3 1
A persistent() 0 4 1
A __construct() 0 21 1
A setWriteFunction() 0 3 1
A getUrl() 0 3 1
A header() 0 4 1
A onCallback() 0 10 4
A getHeaders() 0 7 2
A attachFiles() 0 11 2
A option() 0 4 1
A getRequestExtendedInfo() 0 7 3
A setCallback() 0 4 1
A verbose() 0 4 1
A setCallbackFunction() 0 3 1
A setHeaderFunction() 0 3 1
A httpCompression() 0 9 2
A isResultFile() 0 3 2
A parameters_json() 0 23 5
F prepareRequest() 0 65 14
A GET() 0 3 1
A setResponse() 0 3 1
A getResultFileHandle() 0 3 1
A execute() 0 4 1
A OPTIONS() 0 3 1
A setConnectTimeout() 0 5 1
A auth() 0 4 1
A setFunctionProgress() 0 8 2
A isResponseExists() 0 3 1
A parameters() 0 4 1
A setTimeout() 0 5 1
A handle() 0 4 1
A POST() 0 3 1
A response() 0 7 2
A getDnsCache() 0 3 1
A setDnsCache() 0 4 1
A PUT() 0 3 1
A setResultFileHandle() 0 8 2

How to fix   Complexity   

Complex Class

Complex classes like CurlerRequest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use CurlerRequest, and based on these observations, apply Extract Interface, too.

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
use const CURLOPT_HTTPGET;
7
use const CURLOPT_POST;
8
9
class CurlerRequest
10
{
11
    /**
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...
12
     * @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...
13
     */
14
    public $extendinfo = array();
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
15
16
    /**
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...
17
     * @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...
18
     */
19
    private $parameters = '';
20
21
    /**
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...
22
     * @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...
23
     */
24
    private $options;
25
26
    /**
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...
27
     * @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...
28
     */
29
    private $headers; // Parsed reponse header object.
30
31
    /**
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...
32
     * @var string
33
     */
34
    private $url;
35
36
    /**
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...
37
     * @var string
38
     */
39
    private $method;
40
41
    /**
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...
42
     * @var bool
43
     */
44
    private $id;
45
46
    /**
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...
47
     * @var resource|null
48
     */
49
    private $handle;
50
51
    /** @var CurlerResponse */
52
    private $response;
53
54
    /** @var bool */
55
    private $_persistent = false;
56
57
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$_attachFiles with single line content, use one-line comment instead.
Loading history...
58
     * @var bool
59
     */
60
    private $_attachFiles = false;
61
62
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$callback_class with single line content, use one-line comment instead.
Loading history...
63
     * @var string
64
     */
65
    private $callback_class = '';
66
67
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$callback_functionName with single line content, use one-line comment instead.
Loading history...
68
     * @var string
69
     */
70
    private $callback_functionName = '';
71
72
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$_httpCompression with single line content, use one-line comment instead.
Loading history...
73
     * @var bool
74
     */
75
    private $_httpCompression = false;
76
77
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$callback_function with single line content, use one-line comment instead.
Loading history...
78
     * @var callable
79
     */
80
    private $callback_function = null;
81
82
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$infile_handle with single line content, use one-line comment instead.
Loading history...
83
     * @var bool|resource
84
     */
85
    private $infile_handle = false;
86
87
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$_dns_cache with single line content, use one-line comment instead.
Loading history...
88
     * @var int
89
     */
90
    private $_dns_cache = 120;
91
92
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$resultFileHandle with single line content, use one-line comment instead.
Loading history...
93
     * @var resource
94
     */
95
    private $resultFileHandle = null;
96
97
    /**
98
     * @param bool $id
99
     */
100 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...
101
    {
102 63
        $this->id = $id;
103
104 63
        $this->header('Cache-Control', 'no-cache, no-store, must-revalidate');
105 63
        $this->header('Expires', '0');
106 63
        $this->header('Pragma', 'no-cache');
107
108 63
        $this->options = array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
109 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...
110 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...
111 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...
112 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...
113 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...
114 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...
115 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...
116 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...
117 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...
118 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...
119 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...
120 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...
121
        );
122 63
    }
123
124
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
125
     *
126
     */
127 63
    public function __destruct()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::__destruct() does not need documentation comment.
Loading history...
128
    {
129 63
        $this->close();
130 63
    }
131
132
133 63
    public function close()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::close() does not have void return type hint.
Loading history...
134
    {
135 63
        if ($this->handle)
136
        {
137 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...
138
        }
139 63
        $this->handle = null;
140 63
    }
141
142
    /**
143
     * @param array $attachFiles
0 ignored issues
show
introduced by
@param annotation of method \ClickHouseDB\Transport\CurlerRequest::attachFiles() does not specify type hint for items of its traversable parameter $attachFiles.
Loading history...
144
     */
145 1
    public function attachFiles($attachFiles)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::attachFiles() does not have parameter type hint for its parameter $attachFiles but it should be possible to add it based on @param annotation "array".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::attachFiles() does not have void return type hint.
Loading history...
146
    {
147 1
        $this->header("Content-Type", "multipart/form-data");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Content-Type does not require double quotes, as per coding-style, please use single quotes.

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

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

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

<?php

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

print $doubleQuoted;

will print an indented: Single is Value

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

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

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

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

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

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

<?php

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

print $doubleQuoted;

will print an indented: Single is Value

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

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

Loading history...
148
149 1
        $out = [];
150 1
        foreach ($attachFiles as $post_name => $file_path) {
151 1
            $out[$post_name] = new \CURLFile($file_path);
0 ignored issues
show
introduced by
Class \CURLFile should not be referenced via a fully qualified name, but via a use statement.
Loading history...
152
        }
153
154 1
        $this->_attachFiles = true;
155 1
        $this->parameters($out);
156 1
    }
157
158
159
    /**
160
     * @param bool $set
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
161
     * @return $this
162
     */
163
    public function id($set = false)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::id() does not have parameter type hint for its parameter $set but it should be possible to add it based on @param annotation "bool".
Loading history...
164
    {
165
        if ($set) {
166
            $this->id = $set;
167
        }
168
169
        return $this;
170
    }
171
172
    /**
173
     * @param array $params
0 ignored issues
show
introduced by
@param annotation of method \ClickHouseDB\Transport\CurlerRequest::setRequestExtendedInfo() does not specify type hint for items of its traversable parameter $params.
Loading history...
introduced by
Incorrect annotations group.
Loading history...
174
     * @return $this
175
     */
176 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...
177
    {
178 63
        $this->extendinfo = $params;
179 63
        return $this;
180
    }
181
182
    /**
183
     * @param string|integer|null $key
0 ignored issues
show
introduced by
Expected "int" but found "integer" in @param annotation.
Loading history...
introduced by
Incorrect annotations group.
Loading history...
184
     * @return mixed
185
     */
186 63
    public function getRequestExtendedInfo($key = null)
187
    {
188 63
        if ($key) {
189 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...
190
        }
191
192
        return $this->extendinfo;
193
    }
194
195
    /**
196
     * @return bool|resource
197
     */
198 8
    public function getInfileHandle()
199
    {
200 8
        return $this->infile_handle;
201
    }
202
203
    /**
204
     * @param string $file_name
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
205
     * @return bool|resource
206
     */
207 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...
208
    {
209 8
        $this->header('Expect', '');
210 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...
211 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...
212
        {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
213
214 8
            if ($this->_httpCompression) {
215 8
                $this->header('Content-Encoding', 'gzip');
216 8
                $this->header('Content-Type', 'application/x-www-form-urlencoded');
217
218 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...
219
220 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...
221
            } else {
222
                $this->options[CURLOPT_INFILESIZE] = filesize($file_name);
0 ignored issues
show
introduced by
Constant CURLOPT_INFILESIZE should not be referenced via a fallback global name, but via a use statement.
Loading history...
introduced by
Function filesize() should not be referenced via a fallback global name, but via a use statement.
Loading history...
223
            }
224
225 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...
226
        }
227
228 8
        return $this->infile_handle;
229
    }
230
231
    /**
232
     * @param callable $callback
233
     */
234 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...
235
    {
236 8
        $this->callback_function = $callback;
237 8
    }
238
239
    /**
240
     * @param callable $callback
241
     */
242 1
    public function setWriteFunction($callback)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setWriteFunction() does not have parameter type hint for its parameter $callback but it should be possible to add it based on @param annotation "callable".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setWriteFunction() does not have void return type hint.
Loading history...
243
    {
244 1
        $this->options[CURLOPT_WRITEFUNCTION]=$callback;
0 ignored issues
show
introduced by
Constant CURLOPT_WRITEFUNCTION should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
245 1
    }
246
    /**
247
     * @param callable $callback
248
     */
249 3
    public function setReadFunction($callback)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setReadFunction() does not have parameter type hint for its parameter $callback but it should be possible to add it based on @param annotation "callable".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setReadFunction() does not have void return type hint.
Loading history...
250
    {
251 3
        $this->options[CURLOPT_READFUNCTION] = $callback;
0 ignored issues
show
introduced by
Constant CURLOPT_READFUNCTION should not be referenced via a fallback global name, but via a use statement.
Loading history...
252 3
    }
253
254
    public function setHeaderFunction($callback)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setHeaderFunction() does not have parameter type hint nor @param annotation for its parameter $callback.
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setHeaderFunction() does not have void return type hint.
Loading history...
255
    {
256
        $this->options[CURLOPT_HEADERFUNCTION] = $callback;
0 ignored issues
show
introduced by
Constant CURLOPT_HEADERFUNCTION should not be referenced via a fallback global name, but via a use statement.
Loading history...
257
    }
258
259
    /**
260
     * @param string $classCallBack
261
     * @param string $functionName
262
     */
263
    public function setCallback($classCallBack, $functionName)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setCallback() does not have parameter type hint for its parameter $classCallBack but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setCallback() does not have parameter type hint for its parameter $functionName but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setCallback() does not have void return type hint.
Loading history...
264
    {
265
        $this->callback_class = $classCallBack;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

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

To visualize

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

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

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

will produce no issues.

Loading history...
266
        $this->callback_functionName = $functionName;
267
    }
268
269
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
270
     *
271
     */
272 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...
273
    {
274 10
        if ($this->callback_function) {
275 8
            $x = $this->callback_function;
276 8
            $x($this);
277
        }
278
279 10
        if ($this->callback_class && $this->callback_functionName) {
0 ignored issues
show
introduced by
Use early exit to reduce code nesting.
Loading history...
280
            $c = $this->callback_functionName;
281
            $this->callback_class->$c($this);
282
        }
283 10
    }
284
285
    /**
286
     * @param bool $result
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
287
     * @return string
288
     */
289
    public function dump($result = false)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::dump() does not have parameter type hint for its parameter $result but it should be possible to add it based on @param annotation "bool".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::dump() does not have return type hint for its return value but it should be possible to add it based on @return annotation "string".
Loading history...
290
    {
291
        $message = "\n------------  Request ------------\n";
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

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

To visualize

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

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

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

will produce no issues.

Loading history...
292
        $message .= 'URL:' . $this->url . "\n\n";
293
        $message .= 'METHOD:' . $this->method . "\n\n";
294
        $message .= 'PARAMS:' . print_r($this->parameters, true) . "\n";
0 ignored issues
show
introduced by
Function print_r() should not be referenced via a fallback global name, but via a use statement.
Loading history...
295
        $message .= 'PARAMS:' . print_r($this->headers, true) . "\n";
0 ignored issues
show
introduced by
Function print_r() should not be referenced via a fallback global name, but via a use statement.
Loading history...
296
        $message .= "-----------------------------------\n";
297
298
        if ($result) {
299
            return $message;
300
        }
301
302
        echo $message;
303
        return '';
304
    }
305
306
    /**
307
     * @return bool
308
     */
309 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...
310
    {
311 13
        return $this->id;
312
    }
313
314
    /**
315
     * @param integer $key
0 ignored issues
show
introduced by
Expected "int" but found "integer" in @param annotation.
Loading history...
introduced by
Incorrect annotations group.
Loading history...
316
     * @param mixed $value
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
317
     * @return $this
318
     */
319 1
    private function option($key, $value)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::option() does not have parameter type hint for its parameter $key but it should be possible to add it based on @param annotation "integer".
Loading history...
320
    {
321 1
        $this->options[$key] = $value;
322 1
        return $this;
323
    }
324
325
    /**
326
     * @return $this
327
     */
328 1
    public function persistent()
329
    {
330 1
        $this->_persistent = true;
331 1
        return $this;
332
    }
333
334
    /**
335
     * @return bool
336
     */
337 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...
338
    {
339 10
        return $this->_persistent;
340
    }
341
342
    /**
343
     * @param int $sec
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
344
     * @return $this
345
     */
346 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...
347
    {
348 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...
349 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...
350 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...
351
352 63
        return $this;
353
    }
354
355
    /**
356
     * @param bool $flag
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
357
     * @return $this
358
     */
359 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...
360
    {
361 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...
362 63
        return $this;
363
    }
364
365
    /**
366
     * @param string $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
367
     * @param string $value
368
     * @return $this
369
     */
370 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...
371
    {
372 63
        $this->headers[$key] = $value;
373 63
        return $this;
374
    }
375
376
    /**
377
     * @return array
0 ignored issues
show
introduced by
@return annotation of method \ClickHouseDB\Transport\CurlerRequest::getHeaders() does not specify type hint for items of its traversable return value.
Loading history...
378
     */
379
    public function getHeaders()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::getHeaders() does not have return type hint for its return value but it should be possible to add it based on @return annotation "array".
Loading history...
380
    {
381
        $head = [];
382
        foreach ($this->headers as $key=>$value) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space before "=>"; 0 found
Loading history...
Coding Style introduced by
Expected 1 space after "=>"; 0 found
Loading history...
383
                    $head[] = sprintf("%s: %s", $key, $value);
0 ignored issues
show
introduced by
Function sprintf() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style Comprehensibility introduced by
The string literal %s: %s does not require double quotes, as per coding-style, please use single quotes.

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

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

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

<?php

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

print $doubleQuoted;

will print an indented: Single is Value

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

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

Loading history...
384
        }
385
        return $head;
386
    }
387
388
    /**
389
     * @param string $url
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
390
     * @return $this
391
     */
392 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...
393
    {
394 63
        $this->url = $url;
395 63
        return $this;
396
    }
397
398
    /**
399
     * @return mixed
400
     */
401
    public function getUrl()
402
    {
403
        return $this->url;
404
    }
405
406
407
    /**
408
     * @param string $id
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
409
     * @return string
410
     */
411 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...
412
    {
413 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...
414
    }
415
416 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...
417
    {
418 63
        if ($flag) {
419 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...
420 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...
421
        } else
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after ELSE keyword; newline found
Loading history...
422
        {
423
            $this->_httpCompression = false;
424
            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...
425
        }
426 63
    }
427
428
    /**
429
     * @param string $username
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
430
     * @param string $password
431
     * @return $this
432
     */
433 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...
434
    {
435 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...
436 63
        return $this;
437
    }
438
439
    /**
440
     * @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...
441
     * @return $this
442
     */
443 1
    public function parameters($data)
444
    {
445 1
        $this->parameters = $data;
446 1
        return $this;
447
    }
448
449
    /**
450
     * The maximum number of seconds (float) allowed to execute cURL functions.
451
     *
452
     * @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...
453
     * @return $this
454
     */
455 63
    public function setTimeout(float $seconds = 10) : self
456
    {
457 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...
458
459 63
        return $this;
460
    }
461
462
    /**
463
     * The number of seconds to wait when trying to connect. Use 0 for infinite waiting.
464
     */
465 63
    public function setConnectTimeout(float $seconds = 1) : self
466
    {
467 63
        $this->options[CURLOPT_CONNECTTIMEOUT_MS] = (int) ($seconds * 1000);
468
469 63
        return $this;
470
    }
471
472
    /**
473
     * @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...
474
     * @return $this
475
     * @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...
476
     */
477 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...
478
    {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
479
480 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...
481 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...
482
483 63
        if ($data === null) {
484
            $this->parameters = '{}';
485
            return $this;
486
        }
487
488 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...
489 63
            $this->parameters = $data;
490 63
            return $this;
491
        }
492
493
        $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...
494
495
        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...
496
            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...
497
        }
498
499
        return $this;
500
    }
501
502
    /**
503
     * @return resource
504
     */
505
    public function getResultFileHandle()
506
    {
507
        return $this->resultFileHandle;
508
    }
509
510
    /**
511
     * @return bool
512
     */
513
    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...
514
    {
515
        return ($this->resultFileHandle ? true : false);
0 ignored issues
show
introduced by
Usage of language construct "return" with parentheses is disallowed.
Loading history...
516
    }
517
518
    /**
519
     * @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...
520
     * @param bool $zlib
0 ignored issues
show
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
521
     * @return $this
522
     */
523 1
    public function setResultFileHandle($h, $zlib = false)
524
    {
525 1
        $this->resultFileHandle = $h;
526 1
        if ($zlib) {
527
            $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...
528
            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...
529
        }
530 1
        return $this;
531
    }
532
533
    /**
534
     * @return CurlerRequest
535
     */
536
    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...
537
    {
538
        return $this->execute('PUT');
539
    }
540
541
    /**
542
     * @return CurlerRequest
543
     */
544 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...
545
    {
546 63
        return $this->execute('POST');
547
    }
548
549
    /**
550
     * @return CurlerRequest
551
     */
552
    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...
553
    {
554
        return $this->execute('OPTIONS');
555
    }
556
557
    /**
558
     * @return CurlerRequest
559
     */
560 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...
561
    {
562 39
        return $this->execute('GET');
563
    }
564
565
    /**
566
     * The number of seconds that DNS records are stored in memory. By default this parameter is 120 (2 minutes).
567
     *
568
     * @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...
569
     * @return $this
570
     */
571
    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...
572
    {
573
        $this->_dns_cache = $set;
574
        return $this;
575
    }
576
577
    /**
578
     * The number of seconds that DNS records are stored in memory. By default this parameter is 120 (2 minutes).
579
     *
580
     * @return int
581
     */
582 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...
583
    {
584 63
        return $this->_dns_cache;
585
    }
586
587
    /**
588
     * @param string $method
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
589
     * @return $this
590
     */
591 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...
592
    {
593 63
        $this->method = $method;
594 63
        return $this;
595
    }
596
597
    /**
598
     * @return CurlerResponse
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
599
     * @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...
600
     */
601 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...
602
    {
603 63
        if (! $this->response) {
604
            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...
605
        }
606
607 63
        return $this->response;
608
    }
609
610 29
    public function isResponseExists() : bool
611
    {
612 29
        return $this->response !== null;
613
    }
614
615 63
    public function setResponse(CurlerResponse $response) : void
616
    {
617 63
        $this->response = $response;
618 63
    }
619
620
    /**
621
     * @return mixed
622
     */
623 63
    public function handle()
624
    {
625 63
        $this->prepareRequest();
626 63
        return $this->handle;
627
    }
628
629
    /**
630
     * @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...
631
     * @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...
632
     */
633 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...
634
    {
635 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...
636
            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...
637
        }
638
639 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...
640 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...
641 1
    }
642
643
644
    /**
645
     * @return bool
646
     */
647 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...
648
    {
649 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...
650 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...
651
        }
652
653 63
        $curl_opt = $this->options;
654 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...
655
656 63
        if ($this->_attachFiles) {
657 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...
658
        }
659
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
660
661 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...
662 39
            $curl_opt[CURLOPT_HTTPGET]       = true;
663 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...
664 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...
665
        } else {
666 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...
667 63
                $curl_opt[CURLOPT_POST] = true;
668
            }
669
670 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...
671
672 63
            if ($this->parameters) {
673 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...
674
675 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...
676 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...
677
                }
678
            }
679
        }
680
        // CURLOPT_DNS_CACHE_TIMEOUT - Количество секунд, в течение которых в памяти хранятся DNS-записи.
681 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...
682 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...
683
684 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...
685 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...
686
687 63
            foreach ($this->headers as $key => $value) {
688 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...
689
            }
690
        }
691
692 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...
693
694 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...
695
        }
696
697 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...
698
        {
699 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...
700
        }
701
702 63
        if ($this->resultFileHandle) {
703 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...
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...
705
        }
706
707 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...
708
            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...
709
        }
710 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...
711 63
        return true;
712
    }
713
}
714