Passed
Pull Request — master (#220)
by
unknown
09:01
created

CurlerRequest   F

Complexity

Total Complexity 90

Size/Duplication

Total Lines 759
Duplicated Lines 0 %

Test Coverage

Coverage 72.82%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 216
c 2
b 1
f 0
dl 0
loc 759
ccs 185
cts 254
cp 0.7282
rs 2
wmc 90

52 Methods

Rating   Name   Duplication   Size   Complexity  
A keepAlive() 0 4 1
A httpCompression() 0 8 2
A getUniqHash() 0 3 1
A isResultFile() 0 3 2
A parameters_json() 0 23 5
A setReadFunction() 0 3 1
A isPersistent() 0 3 1
A dump() 0 15 2
F prepareRequest() 0 76 18
A setInfile() 0 21 3
A GET() 0 3 1
A setStdErrOut() 0 4 2
A url() 0 4 1
A id() 0 7 2
A getId() 0 3 1
A getResultFileHandle() 0 3 1
A setResponse() 0 3 1
A execute() 0 4 1
A OPTIONS() 0 3 1
A timeOut() 0 3 1
A timeOutMs() 0 4 1
A persistent() 0 4 1
A __construct() 0 23 1
A authByBasicAuth() 0 4 1
A setFunctionProgress() 0 8 2
A setWriteFunction() 0 3 1
A getUrl() 0 3 1
A isResponseExists() 0 3 1
A getInfileHandle() 0 3 1
A getDetails() 0 7 1
A header() 0 4 1
A onCallback() 0 10 4
A getHeaders() 0 7 2
A parameters() 0 4 1
A connectTimeOut() 0 4 1
A attachFiles() 0 11 2
A setRequestExtendedInfo() 0 4 1
A option() 0 4 1
A setSslCa() 0 4 1
A handle() 0 4 1
A POST() 0 3 1
A getRequestExtendedInfo() 0 7 3
A setCallback() 0 4 1
A response() 0 7 2
A verbose() 0 4 1
A authByHeaders() 0 5 1
A getDnsCache() 0 3 1
A setDnsCache() 0 4 1
A setCallbackFunction() 0 3 1
A setHeaderFunction() 0 3 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_HTTPGET;
6
use const CURLOPT_POST;
7
8
class CurlerRequest
9
{
10
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$extendinfo with single line content, use one-line comment instead.
Loading history...
11
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Transport\CurlerRequest::$extendinfo does not specify type hint for its items.
Loading history...
12
     */
13
    public $extendinfo = [];
14
15
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$parameters with single line content, use one-line comment instead.
Loading history...
16
     * @var string|array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Transport\CurlerRequest::$parameters does not specify type hint for its items.
Loading history...
17
     */
18
    private $parameters = '';
19
20
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$options with single line content, use one-line comment instead.
Loading history...
21
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Transport\CurlerRequest::$options does not specify type hint for its items.
Loading history...
22
     */
23
    private $options;
24
25
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$headers with single line content, use one-line comment instead.
Loading history...
26
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \ClickHouseDB\Transport\CurlerRequest::$headers does not specify type hint for its items.
Loading history...
27
     */
28
    private $headers; // Parsed reponse header object.
29
30
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$url with single line content, use one-line comment instead.
Loading history...
31
     * @var string
32
     */
33
    private $url;
34
35
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$method with single line content, use one-line comment instead.
Loading history...
36
     * @var string
37
     */
38
    private $method;
39
40
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$id with single line content, use one-line comment instead.
Loading history...
41
     * @var bool
42
     */
43
    private $id;
44
45
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$handle with single line content, use one-line comment instead.
Loading history...
46
     * @var resource|null
47
     */
48
    private $handle;
49
50
    /** @var CurlerResponse */
51
    private $response;
52
53
    /** @var bool */
54
    private $_persistent = false;
55
56
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$_attachFiles with single line content, use one-line comment instead.
Loading history...
57
     * @var bool
58
     */
59
    private $_attachFiles = false;
60
61
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$callback_class with single line content, use one-line comment instead.
Loading history...
62
     * @var string
63
     */
64
    private $callback_class = '';
0 ignored issues
show
Coding Style introduced by
Member variable "callback_class" is not in valid camel caps format
Loading history...
65
66
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$callback_functionName with single line content, use one-line comment instead.
Loading history...
67
     * @var string
68
     */
69
    private $callback_functionName = '';
0 ignored issues
show
Coding Style introduced by
Member variable "callback_functionName" is not in valid camel caps format
Loading history...
70
71
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$_httpCompression with single line content, use one-line comment instead.
Loading history...
72
     * @var bool
73
     */
74
    private $_httpCompression = false;
75
76
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$callback_function with single line content, use one-line comment instead.
Loading history...
77
     * @var callable
78
     */
79
    private $callback_function = null;
0 ignored issues
show
Coding Style introduced by
Member variable "callback_function" is not in valid camel caps format
Loading history...
80
81
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$infile_handle with single line content, use one-line comment instead.
Loading history...
82
     * @var bool|resource
83
     */
84
    private $infile_handle = false;
0 ignored issues
show
Coding Style introduced by
Member variable "infile_handle" is not in valid camel caps format
Loading history...
85
86
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$_dns_cache with single line content, use one-line comment instead.
Loading history...
87
     * @var int
88
     */
89
    private $_dns_cache = 120;
0 ignored issues
show
Coding Style introduced by
Member variable "_dns_cache" is not in valid camel caps format
Loading history...
90
91
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$resultFileHandle with single line content, use one-line comment instead.
Loading history...
92
     * @var resource
93
     */
94
    private $resultFileHandle = null;
95
96
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$sslCa with single line content, use one-line comment instead.
Loading history...
97
     * @var string
98
     */
99
    private $sslCa = null;
0 ignored issues
show
introduced by
The private property $sslCa is not used, and could be removed.
Loading history...
100
101
102
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \ClickHouseDB\Transport\CurlerRequest::$stdErrOut with single line content, use one-line comment instead.
Loading history...
103
     * @var null|resource
0 ignored issues
show
introduced by
Null type hint should be on last position in "null|resource".
Loading history...
104 54
     */
105
    private $stdErrOut = null;
106 54
    /**
107
     * @param bool $id
108 54
     */
109 54
    public function __construct($id = false, $handle = null)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::__construct() does not have native type hint for its parameter $id but it should be possible to add it based on @param annotation "bool".
Loading history...
Coding Style introduced by
Expected 1 blank line before function; 0 found
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::__construct() does not have parameter type hint nor @param annotation for its parameter $handle.
Loading history...
110 54
    {
111
        $this->id = $id;
112 54
113 54
        $this->header('Cache-Control', 'no-cache, no-store, must-revalidate');
114 54
        $this->header('Expires', '0');
115 54
        $this->header('Pragma', 'no-cache');
116 54
117 54
        $this->options = array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
118 54
            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...
119 54
            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...
120 54
            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...
121 54
            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...
122 54
            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...
123 54
            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...
124 54
            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...
125
            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...
126 54
            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...
127
            CURLOPT_BINARYTRANSFER => 1, // передавать в binary-safe
0 ignored issues
show
introduced by
The constant CURLOPT_BINARYTRANSFER has been deprecated: 5.1.3 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

127
            /** @scrutinizer ignore-deprecated */ CURLOPT_BINARYTRANSFER => 1, // передавать в binary-safe
Loading history...
introduced by
Constant CURLOPT_BINARYTRANSFER should not be referenced via a fallback global name, but via a use statement.
Loading history...
128
            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...
129
            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...
130
        );
131 49
        $this->handle = $handle;
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...
132
    }
133 49
134 49
    /**
135
     * @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...
136
     */
137 49
    public function attachFiles($attachFiles)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::attachFiles() does not have native 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...
138
    {
139 49
        $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...
140 49
141
        $out = [];
142 49
        foreach ($attachFiles as $post_name => $file_path) {
0 ignored issues
show
Coding Style introduced by
The variable $post_name should be in camel caps format.
Loading history...
Coding Style introduced by
The variable $file_path should be in camel caps format.
Loading history...
143 49
            $out[$post_name] = new \CURLFile($file_path);
0 ignored issues
show
Coding Style introduced by
The variable $post_name should be in camel caps format.
Loading history...
introduced by
Class \CURLFile should not be referenced via a fully qualified name, but via a use statement.
Loading history...
Coding Style introduced by
The variable $file_path should be in camel caps format.
Loading history...
144
        }
145
146
        $this->_attachFiles = true;
147
        $this->parameters($out);
148 1
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
149
150 1
151
    /**
152 1
     * @param bool $set
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
153 1
     * @return $this
154 1
     */
155
    public function id($set = false)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::id() does not have native type hint for its parameter $set but it should be possible to add it based on @param annotation "bool".
Loading history...
156
    {
157 1
        if ($set) {
158 1
            $this->id = $set;
159 1
        }
160
161
        return $this;
162
    }
163
164
    /**
165
     * @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...
166
     * @return $this
167
     */
168
    public function setRequestExtendedInfo($params)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setRequestExtendedInfo() does not have native type hint for its parameter $params but it should be possible to add it based on @param annotation "array".
Loading history...
169
    {
170
        $this->extendinfo = $params;
171
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
172
    }
173
174
    /**
175
     * @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...
176
     * @return mixed
177
     */
178
    public function getRequestExtendedInfo($key = null)
179 45
    {
180
        if ($key) {
181 45
            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...
182 45
        }
183
184
        return $this->extendinfo;
185
    }
186
187
    /**
188
     * @return bool|resource
189 45
     */
190
    public function getInfileHandle()
191 45
    {
192 45
        return $this->infile_handle;
0 ignored issues
show
Coding Style introduced by
Member variable "infile_handle" is not in valid camel caps format
Loading history...
193
    }
194
195
    /**
196
     * @param string $file_name
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
197
     * @return bool|resource
198
     */
199
    public function setInfile($file_name)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setInfile() does not have native type hint for its parameter $file_name but it should be possible to add it based on @param annotation "string".
Loading history...
Coding Style introduced by
The variable $file_name should be in camel caps format.
Loading history...
200
    {
201 8
        $this->header('Expect', '');
202
        $this->infile_handle = fopen($file_name, 'r');
0 ignored issues
show
Coding Style introduced by
Member variable "infile_handle" is not in valid camel caps format
Loading history...
introduced by
Function fopen() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
The variable $file_name should be in camel caps format.
Loading history...
203 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...
Coding Style introduced by
Member variable "infile_handle" is not in valid camel caps format
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
204
205
            if ($this->_httpCompression) {
206
                $this->header('Content-Encoding', 'gzip');
207
                $this->header('Content-Type', 'application/x-www-form-urlencoded');
208
209
                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...
Coding Style introduced by
Member variable "infile_handle" is not in valid camel caps format
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...
210 8
211
                $this->options[CURLOPT_SAFE_UPLOAD] = 1;
0 ignored issues
show
introduced by
The constant CURLOPT_SAFE_UPLOAD has been deprecated: 7.0 Use <b>CURLFile</b> for uploads instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

211
                $this->options[/** @scrutinizer ignore-deprecated */ CURLOPT_SAFE_UPLOAD] = 1;
Loading history...
introduced by
Constant CURLOPT_SAFE_UPLOAD should not be referenced via a fallback global name, but via a use statement.
Loading history...
212 8
            } else {
213 8
                $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...
Coding Style introduced by
The variable $file_name should be in camel caps format.
Loading history...
214 8
            }
215
216 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...
Coding Style introduced by
Member variable "infile_handle" is not in valid camel caps format
Loading history...
217 8
        }
218 8
219
        return $this->infile_handle;
0 ignored issues
show
Coding Style introduced by
Member variable "infile_handle" is not in valid camel caps format
Loading history...
220 8
    }
221
222 8
    /**
223
     * @param callable $callback
224
     */
225
    public function setCallbackFunction($callback)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setCallbackFunction() does not have native 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...
226
    {
227 8
        $this->callback_function = $callback;
0 ignored issues
show
Coding Style introduced by
Member variable "callback_function" is not in valid camel caps format
Loading history...
228
    }
229
230 8
    /**
231
     * @param callable $callback
232
     */
233
    public function setWriteFunction($callback)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setWriteFunction() does not have native 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...
234
    {
235
        $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...
236 8
    }
237
238 8
    /**
239 8
     * @param callable $callback
240
     */
241
    public function setReadFunction($callback)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setReadFunction() does not have native 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...
242
    {
243
        $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...
244 1
    }
245
246 1
    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...
247 1
    {
248
        $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...
249
    }
250
251
    /**
252 3
     * @param string $classCallBack
253
     * @param string $functionName
254 3
     */
255 3
    public function setCallback($classCallBack, $functionName)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setCallback() does not have native 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 native 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...
256
    {
257
        $this->callback_class = $classCallBack;
0 ignored issues
show
Coding Style introduced by
Member variable "callback_class" is not in valid camel caps format
Loading history...
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...
258
        $this->callback_functionName = $functionName;
0 ignored issues
show
Coding Style introduced by
Member variable "callback_functionName" is not in valid camel caps format
Loading history...
259
    }
260
261
    /**
0 ignored issues
show
introduced by
Empty comment
Loading history...
262
     *
263
     */
264
    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...
265
    {
266
        if ($this->callback_function) {
0 ignored issues
show
Coding Style introduced by
Member variable "callback_function" is not in valid camel caps format
Loading history...
267
            $x = $this->callback_function;
0 ignored issues
show
Coding Style introduced by
Member variable "callback_function" is not in valid camel caps format
Loading history...
268
            $x($this);
269
        }
270
271
        if ($this->callback_class && $this->callback_functionName) {
0 ignored issues
show
introduced by
Use early exit to reduce code nesting.
Loading history...
Coding Style introduced by
Member variable "callback_class" is not in valid camel caps format
Loading history...
Coding Style introduced by
Member variable "callback_functionName" is not in valid camel caps format
Loading history...
272
            $c = $this->callback_functionName;
0 ignored issues
show
Coding Style introduced by
Member variable "callback_functionName" is not in valid camel caps format
Loading history...
273
            $this->callback_class->$c($this);
0 ignored issues
show
Coding Style introduced by
Member variable "callback_class" is not in valid camel caps format
Loading history...
274
        }
275 10
    }
276
277 10
    public function getDetails(): array
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::getDetails() does not have @return annotation for its traversable return value.
Loading history...
278 8
    {
279 8
        return [
280
            'url'        => $this->url,
281
            'method'     => $this->method,
282 10
            'parameters' => $this->parameters,
283
            'headers'    => $this->headers,
284
        ];
285
    }
286 10
287
    /**
288 1
     * @param resource $stream
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
289
     * @return void
290
     */
291 1
    public function setStdErrOut($stream)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setStdErrOut() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "void".
Loading history...
292 1
    {
293 1
        if (is_resource($stream)) {
0 ignored issues
show
introduced by
Expected 0 lines after "if", found 1.
Loading history...
introduced by
Use early exit to reduce code nesting.
Loading history...
introduced by
Function is_resource() should not be referenced via a fallback global name, but via a use statement.
Loading history...
294 1
            $this->stdErrOut=$stream;
0 ignored issues
show
Coding Style introduced by
Expected at least 1 space before "="; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "="; 0 found
Loading history...
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
295
        }
296
297
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
298
299
    /**
300
     * @param bool $result
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
301
     * @return string
302
     */
303
    public function dump($result = false)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::dump() does not have native 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 native return type hint for its return value but it should be possible to add it based on @return annotation "string".
Loading history...
304
    {
305
        $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...
306
        $message .= 'URL:' . $this->url . "\n\n";
307
        $message .= 'METHOD:' . $this->method . "\n\n";
308
        $message .= 'PARAMS:' . print_r($this->parameters, true) . "\n";
0 ignored issues
show
Bug introduced by
Are you sure print_r($this->parameters, true) of type string|true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

308
        $message .= 'PARAMS:' . /** @scrutinizer ignore-type */ print_r($this->parameters, true) . "\n";
Loading history...
introduced by
Function print_r() should not be referenced via a fallback global name, but via a use statement.
Loading history...
309
        $message .= 'PARAMS:' . print_r($this->headers, true) . "\n";
0 ignored issues
show
Bug introduced by
Are you sure print_r($this->headers, true) of type string|true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

309
        $message .= 'PARAMS:' . /** @scrutinizer ignore-type */ print_r($this->headers, true) . "\n";
Loading history...
introduced by
Function print_r() should not be referenced via a fallback global name, but via a use statement.
Loading history...
310
        $message .= "-----------------------------------\n";
311
312
        if ($result) {
313
            return $message;
314
        }
315
316
        echo $message;
317
        return '';
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
318
    }
319
320
    /**
321
     * @return bool
322 15
     */
323
    public function getId()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::getId() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
324 15
    {
325
        return $this->id;
326
    }
327
328
    /**
329
     * @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...
330
     * @param mixed $value
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
331
     * @return $this
332 1
     */
333
    private function option($key, $value)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::option() does not have native type hint for its parameter $key but it should be possible to add it based on @param annotation "integer".
Loading history...
334 1
    {
335 1
        $this->options[$key] = $value;
336
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
337
    }
338
339
    /**
340
     * @return $this
341 1
     */
342
    public function persistent()
343 1
    {
344 1
        $this->_persistent = true;
345
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
346
    }
347
348
    /**
349
     * @return bool
350 10
     */
351
    public function isPersistent()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::isPersistent() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
352 10
    {
353
        return $this->_persistent;
354
    }
355
356
    /**
357
     * @param int $sec
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::keepAlive() has useless @param annotation for parameter $sec.
Loading history...
358
     * @return $this
359
     */
360
    public function keepAlive(int $sec = 60)
361
    {
362
        $this->headers['Connection'] = 'keep-alive';
363
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
364
    }
365
366
    /**
367
     * @param bool $flag
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::verbose() has useless @param annotation for parameter $flag.
Loading history...
368
     * @return $this
369
     */
370
    public function verbose(bool $flag = true)
371
    {
372 54
        $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...
373
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
374 54
    }
375 54
376
    /**
377
     * @param string $key
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::header() has useless @param annotation for parameter $key.
Loading history...
378
     * @param string $value
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::header() has useless @param annotation for parameter $value.
Loading history...
379
     * @return $this
380
     */
381
    public function header(string $key, string $value)
382
    {
383 54
        $this->headers[$key] = $value;
384
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
385 54
    }
386 54
387
    /**
388
     * @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...
389
     */
390
    public function getHeaders():array
0 ignored issues
show
introduced by
There must be exactly one space between return type hint colon and return type hint.
Loading history...
391
    {
392
        $head = [];
393
        foreach ($this->headers as $key => $value) {
0 ignored issues
show
introduced by
Expected 1 lines after "foreach", found 0.
Loading history...
394
            $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...
395
        }
396
        return $head;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
397
    }
398
399
    /**
400
     * @param string $url
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::url() has useless @param annotation for parameter $url.
Loading history...
401
     * @return $this
402
     */
403
    public function url(string $url)
404
    {
405 54
        $this->url = $url;
406
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
407 54
    }
408 54
409
    /**
410
     * @return string
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::getUrl() has useless @return annotation.
Loading history...
411
     */
412
    public function getUrl():string
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::getUrl() does not need documentation comment.
Loading history...
introduced by
There must be exactly one space between return type hint colon and return type hint.
Loading history...
413
    {
414
        return $this->url;
415
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
416
417
418
    /**
419
     * @param string $id
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::getUniqHash() has useless @param annotation for parameter $id.
Loading history...
420
     * @return string
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::getUniqHash() has useless @return annotation.
Loading history...
421
     */
422
    public function getUniqHash(string $id):string
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::getUniqHash() does not need documentation comment.
Loading history...
introduced by
There must be exactly one space between return type hint colon and return type hint.
Loading history...
423
    {
424 15
        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...
425
    }
426 15
427
    /**
428
     * @param bool $flag
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::httpCompression() has useless @param annotation for parameter $flag.
Loading history...
429
     */
430
    public function httpCompression(bool $flag):void
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::httpCompression() does not need documentation comment.
Loading history...
introduced by
There must be exactly one space between return type hint colon and return type hint.
Loading history...
431
    {
432 45
        if ($flag) {
433
            $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...
434 45
            $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...
435 45
        } else {
436 45
            $this->_httpCompression = false;
437
            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...
438
        }
439
    }
440
441 45
    /**
442
     * @param string $username
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
443
     * @param string $password
444
     * @return $this
445
     */
446
    public function authByBasicAuth($username, $password)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::authByBasicAuth() does not have native 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::authByBasicAuth() does not have native type hint for its parameter $password but it should be possible to add it based on @param annotation "string".
Loading history...
447
    {
448
        $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...
449
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
450
    }
451
452
    public function authByHeaders($username, $password)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::authByHeaders() does not have parameter type hint nor @param annotation for its parameter $username.
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::authByHeaders() does not have parameter type hint nor @param annotation for its parameter $password.
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::authByHeaders() does not have return type hint nor @return annotation for its return value.
Loading history...
453
    {
454 45
        $this->headers['X-ClickHouse-User'] = $username;
455
        $this->headers['X-ClickHouse-Key'] = $password;
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...
456 45
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
457 45
    }
458 45
459
    /**
460
     * @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...
461
     * @return $this
462
     */
463
    public function parameters($data)
464
    {
465 1
        $this->parameters = $data;
466
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
467 1
    }
468 1
469
    /**
470
     * The number of seconds to wait when trying to connect. Use 0 for infinite waiting.
471
     *
472
     * @param float $seconds
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::connectTimeOut() has useless @param annotation for parameter $seconds.
Loading history...
473
     * @return $this
474
     */
475
    public function connectTimeOut(float $seconds = 1.0)
476
    {
477 54
        $this->options[CURLOPT_CONNECTTIMEOUT_MS] = (int) ($seconds*1000.0);
0 ignored issues
show
introduced by
Constant CURLOPT_CONNECTTIMEOUT_MS should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Expected at least 1 space before "*"; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "*"; 0 found
Loading history...
478
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
479 54
    }
480 54
481
    /**
482
     * The maximum number of seconds (float) allowed to execute cURL functions.
483
     *
484
     * @param float $seconds
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::timeOut() has useless @param annotation for parameter $seconds.
Loading history...
485
     * @return $this
486
     */
487
    public function timeOut(float $seconds = 10)
488
    {
489 45
        return $this->timeOutMs((int) ($seconds * 1000.0));
490
    }
491 45
492
    /**
493
     * The maximum allowed number of milliseconds to perform cURL functions.
494
     *
495
     * @param int $ms millisecond
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
496
     * @return $this
497
     */
498
    protected function timeOutMs(int $ms = 10000)
499
    {
500 45
        $this->options[CURLOPT_TIMEOUT_MS] = $ms;
0 ignored issues
show
introduced by
Constant CURLOPT_TIMEOUT_MS should not be referenced via a fallback global name, but via a use statement.
Loading history...
501
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
502 45
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
503 45
504
505
    /**
506
     * @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...
507
     * @return $this
508
     * @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...
509
     */
510
    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...
511
    {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
512 45
513
        $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...
514
        $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...
515 45
516 45
        if ($data === null) {
517
            $this->parameters = '{}';
518 45
            return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
519
        }
520
521
        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...
522
            $this->parameters = $data;
523 45
            return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
524 45
        }
525 45
526
        $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...
527
528
        if (!$this->parameters && $data) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after NOT operator; 0 found
Loading history...
529
            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...
530
        }
531
532
        return $this;
533
    }
534
535
    /**
536
     * @return resource
537
     */
538
    public function getResultFileHandle()
539
    {
540
        return $this->resultFileHandle;
541
    }
542
543
    /**
544
     * @return bool
545
     */
546
    public function isResultFile()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::isResultFile() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
547
    {
548
        return ($this->resultFileHandle ? true : false);
0 ignored issues
show
introduced by
Usage of language construct "return" with parentheses is disallowed.
Loading history...
introduced by
Useless ternary operator.
Loading history...
549
    }
550
551
    /**
552
     * @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...
553
     * @param bool $zlib
0 ignored issues
show
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
554
     * @return $this
555
     */
556
    public function setResultFileHandle($h, $zlib = false)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setResultFileHandle() does not have native type hint for its parameter $zlib but it should be possible to add it based on @param annotation "bool".
Loading history...
557
    {
558 1
        $this->resultFileHandle = $h;
559
        if ($zlib) {
0 ignored issues
show
introduced by
Expected 1 lines after "if", found 0.
Loading history...
560 1
            $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...
561 1
            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...
562
        }
563
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
564
    }
565 1
566
    /**
567
     * @return CurlerRequest
568
     */
569
    public function PUT()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::PUT() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "CurlerRequest".
Loading history...
570
    {
571
        return $this->execute('PUT');
572
    }
573
574
    /**
575
     * @return CurlerRequest
576
     */
577
    public function POST()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::POST() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "CurlerRequest".
Loading history...
578
    {
579 45
        return $this->execute('POST');
580
    }
581 45
582
    /**
583
     * @return CurlerRequest
584
     */
585
    public function OPTIONS()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::OPTIONS() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "CurlerRequest".
Loading history...
586
    {
587
        return $this->execute('OPTIONS');
588
    }
589
590
    /**
591
     * @return CurlerRequest
592
     */
593
    public function GET()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::GET() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "CurlerRequest".
Loading history...
594
    {
595 38
        return $this->execute('GET');
596
    }
597 38
598
    /**
599
     * The number of seconds that DNS records are stored in memory. By default this parameter is 120 (2 minutes).
600
     *
601
     * @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...
602
     * @return $this
603
     */
604
    public function setDnsCache($set)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setDnsCache() does not have native type hint for its parameter $set but it should be possible to add it based on @param annotation "integer".
Loading history...
605
    {
606
        $this->_dns_cache = $set;
0 ignored issues
show
Coding Style introduced by
Member variable "_dns_cache" is not in valid camel caps format
Loading history...
607
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
608
    }
609
610
    /**
611
     * The number of seconds that DNS records are stored in memory. By default this parameter is 120 (2 minutes).
612
     *
613
     * @return int
614
     */
615
    public function getDnsCache()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::getDnsCache() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "int".
Loading history...
616
    {
617 49
        return $this->_dns_cache;
0 ignored issues
show
Coding Style introduced by
Member variable "_dns_cache" is not in valid camel caps format
Loading history...
618
    }
619 49
620
    /**
621
     * Sets client certificate
622
     *
623
     * @param string $filePath
624
     */
625
    public function setSslCa($filePath)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setSslCa() does not have native type hint for its parameter $filePath but it should be possible to add it based on @param annotation "string".
Loading history...
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::setSslCa() does not have void return type hint.
Loading history...
626
    {
627
        $this->option(CURLOPT_SSL_VERIFYPEER, true);
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...
628
        $this->option(CURLOPT_CAINFO, $filePath);
0 ignored issues
show
introduced by
Constant CURLOPT_CAINFO should not be referenced via a fallback global name, but via a use statement.
Loading history...
629
    }
630
631
    /**
632
     * @param string $method
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
633
     * @return $this
634
     */
635
    private function execute($method)
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::execute() does not have native type hint for its parameter $method but it should be possible to add it based on @param annotation "string".
Loading history...
636
    {
637 54
        $this->method = $method;
638
        return $this;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
639 54
    }
640 54
641
    /**
642
     * @return CurlerResponse
0 ignored issues
show
introduced by
Incorrect annotations group.
Loading history...
643
     * @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...
644
     */
645
    public function response()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::response() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "CurlerResponse".
Loading history...
646
    {
647 49
        if (!$this->response) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after NOT operator; 0 found
Loading history...
648
            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...
649 49
        }
650
651
        return $this->response;
652
    }
653 49
654
    public function isResponseExists(): bool
655
    {
656 32
        return $this->response !== null;
657
    }
658 32
659
    public function setResponse(CurlerResponse $response): void
660
    {
661 49
        $this->response = $response;
662
    }
663 49
664 49
    /**
665
     * @return mixed
666
     */
667
    public function handle()
668
    {
669 49
        $this->prepareRequest();
670
        return $this->handle;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
671 49
    }
672 49
673
    /**
674
     * @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...
675
     * @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...
676
     */
677
    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...
678
    {
679 1
        if (!is_callable($callback)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after NOT operator; 0 found
Loading history...
introduced by
Function is_callable() should not be referenced via a fallback global name, but via a use statement.
Loading history...
680
            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...
681 1
        }
682
683
        $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...
684
        $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...
685 1
    }
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line after function; 2 found
Loading history...
686 1
687 1
688
    /**
689
     * @return bool
690
     */
691
    private function prepareRequest()
0 ignored issues
show
introduced by
Method \ClickHouseDB\Transport\CurlerRequest::prepareRequest() does not have native return type hint for its return value but it should be possible to add it based on @return annotation "bool".
Loading history...
692
    {
693 49
        if (!$this->handle) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after NOT operator; 0 found
Loading history...
694
            $this->handle = curl_init();
0 ignored issues
show
Documentation Bug introduced by
It seems like curl_init() can also be of type CurlHandle. However, the property $handle is declared as type null|resource. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
introduced by
Function curl_init() should not be referenced via a fallback global name, but via a use statement.
Loading history...
695 49
        }
696 49
697
        $curl_opt = $this->options;
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
698
        $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...
699 49
700 49
        if ($this->_attachFiles) {
0 ignored issues
show
introduced by
Expected 1 lines after "if", found 2.
Loading history...
701
            $curl_opt[CURLOPT_SAFE_UPLOAD] = true;
0 ignored issues
show
introduced by
The constant CURLOPT_SAFE_UPLOAD has been deprecated: 7.0 Use <b>CURLFile</b> for uploads instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

701
            $curl_opt[/** @scrutinizer ignore-deprecated */ CURLOPT_SAFE_UPLOAD] = true;
Loading history...
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
introduced by
Constant CURLOPT_SAFE_UPLOAD should not be referenced via a fallback global name, but via a use statement.
Loading history...
702 49
        }
703 1
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
704
705
        if (strtoupper($method) == 'GET') {
0 ignored issues
show
introduced by
Expected 1 lines after "if", found 0.
Loading history...
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...
706
            $curl_opt[CURLOPT_HTTPGET] = true;
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
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...
707 49
            $curl_opt[CURLOPT_CUSTOMREQUEST] = strtoupper($method);
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
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...
708 38
            $curl_opt[CURLOPT_POSTFIELDS] = false;
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
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...
709 38
        } else {
710 38
            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...
711
                $curl_opt[CURLOPT_POST] = true;
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
712 40
            }
713 40
714
            $curl_opt[CURLOPT_CUSTOMREQUEST] = strtoupper($method);
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
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...
715
716 40
            if ($this->parameters) {
717
                $curl_opt[CURLOPT_POSTFIELDS] = $this->parameters;
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
introduced by
Constant CURLOPT_POSTFIELDS should not be referenced via a fallback global name, but via a use statement.
Loading history...
718 40
719 40
                if (!is_array($this->parameters)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after 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...
720
                    $this->header('Content-Length',  mb_strlen($this->parameters, '8bit'));
0 ignored issues
show
Coding Style introduced by
Expected 1 space after comma in argument list; 2 found
Loading history...
introduced by
Function mb_strlen() should not be referenced via a fallback global name, but via a use statement.
Loading history...
721 40
                }
722 40
            }
723
        }
724
        // CURLOPT_DNS_CACHE_TIMEOUT - Количество секунд, в течение которых в памяти хранятся DNS-записи.
725
        $curl_opt[CURLOPT_DNS_CACHE_TIMEOUT] = $this->getDnsCache();
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
introduced by
Constant CURLOPT_DNS_CACHE_TIMEOUT should not be referenced via a fallback global name, but via a use statement.
Loading history...
726
        $curl_opt[CURLOPT_URL] = $this->url;
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
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...
727 49
728 49
        if (!empty($this->headers) && sizeof($this->headers)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after 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...
729
            $curl_opt[CURLOPT_HTTPHEADER] = [];
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
introduced by
Constant CURLOPT_HTTPHEADER should not be referenced via a fallback global name, but via a use statement.
Loading history...
730 49
731 49
            foreach ($this->headers as $key => $value) {
732
                $curl_opt[CURLOPT_HTTPHEADER][] = sprintf("%s: %s", $key, $value);
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
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...
733 49
            }
734 49
        }
735
736
        if (!empty($curl_opt[CURLOPT_INFILE])) {
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
Coding Style introduced by
Expected 1 space after 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...
737
738 49
            $curl_opt[CURLOPT_PUT] = true;
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
introduced by
Constant CURLOPT_PUT should not be referenced via a fallback global name, but via a use statement.
Loading history...
739
        }
740 8
741
        if (!empty($curl_opt[CURLOPT_WRITEFUNCTION])) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after NOT operator; 0 found
Loading history...
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
introduced by
Constant CURLOPT_WRITEFUNCTION should not be referenced via a fallback global name, but via a use statement.
Loading history...
742
            $curl_opt[CURLOPT_HEADER] = false;
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
introduced by
Constant CURLOPT_HEADER should not be referenced via a fallback global name, but via a use statement.
Loading history...
743 49
        }
744 1
745
        if ($this->resultFileHandle) {
746
            $curl_opt[CURLOPT_FILE] = $this->resultFileHandle;
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
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...
747 49
            $curl_opt[CURLOPT_HEADER] = false;
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
introduced by
Constant CURLOPT_HEADER should not be referenced via a fallback global name, but via a use statement.
Loading history...
748 1
        }
749 1
750
        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...
751
            $msg="\n-----------BODY REQUEST----------\n" . $curl_opt[CURLOPT_POSTFIELDS] . "\n------END--------\n";
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
Coding Style introduced by
Expected at least 1 space before "="; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "="; 0 found
Loading history...
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
introduced by
Constant CURLOPT_POSTFIELDS should not be referenced via a fallback global name, but via a use statement.
Loading history...
752 49
            if ($this->stdErrOut && is_resource($this->stdErrOut)) {
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...
753
                fwrite($this->stdErrOut,$msg);
0 ignored issues
show
introduced by
Function fwrite() should not be referenced via a fallback global name, but via a use statement.
Loading history...
754
            } else {
755 49
                echo $msg;
756 49
            }
757
        }
758
759
        if ($this->stdErrOut) {
760
            if (is_resource($this->stdErrOut)) {
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...
761
                $curl_opt[CURLOPT_STDERR]=$this->stdErrOut;
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
introduced by
Constant CURLOPT_STDERR should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Expected at least 1 space before "="; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "="; 0 found
Loading history...
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces
Loading history...
762
            }
763
        }
764
765
        curl_setopt_array($this->handle, $curl_opt);
0 ignored issues
show
Coding Style introduced by
The variable $curl_opt should be in camel caps format.
Loading history...
introduced by
Function curl_setopt_array() should not be referenced via a fallback global name, but via a use statement.
Loading history...
766
        return true;
0 ignored issues
show
introduced by
Expected 1 lines before "return", found 0.
Loading history...
767
    }
768
}
769