1 | <?php |
||||
0 ignored issues
–
show
introduced
by
![]() |
|||||
2 | |||||
3 | namespace ClickHouseDB\Query; |
||||
4 | |||||
5 | use ClickHouseDB\Exception\QueryException; |
||||
6 | use function sizeof; |
||||
0 ignored issues
–
show
|
|||||
7 | |||||
8 | class Query |
||||
9 | { |
||||
10 | /** |
||||
0 ignored issues
–
show
|
|||||
11 | * @var string |
||||
12 | */ |
||||
13 | protected $sql; |
||||
14 | |||||
15 | /** |
||||
0 ignored issues
–
show
|
|||||
16 | * @var string|null |
||||
17 | */ |
||||
18 | protected $format = null; |
||||
19 | |||||
20 | /** |
||||
0 ignored issues
–
show
|
|||||
21 | * @var array |
||||
0 ignored issues
–
show
|
|||||
22 | */ |
||||
23 | private $degenerations = []; |
||||
24 | |||||
25 | private $supportFormats=[ |
||||
0 ignored issues
–
show
|
|||||
26 | "FORMAT\\s+TSVRaw", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+TSVRaw 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 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 ( 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: 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. ![]() |
|||||
27 | "FORMAT\\s+TSVWithNamesAndTypes", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+TSVWithNamesAndTypes 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 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 ( 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: 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. ![]() |
|||||
28 | "FORMAT\\s+TSVWithNames", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+TSVWithNames 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 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 ( 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: 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. ![]() |
|||||
29 | "FORMAT\\s+TSV", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+TSV 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 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 ( 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: 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. ![]() |
|||||
30 | "FORMAT\\s+Vertical", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+Vertical 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 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 ( 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: 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. ![]() |
|||||
31 | "FORMAT\\s+JSONCompact", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+JSONCompact 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 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 ( 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: 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. ![]() |
|||||
32 | "FORMAT\\s+JSONEachRow", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+JSONEachRow 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 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 ( 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: 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. ![]() |
|||||
33 | "FORMAT\\s+TSKV", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+TSKV 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 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 ( 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: 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. ![]() |
|||||
34 | "FORMAT\\s+TabSeparatedWithNames", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+TabSeparatedWithNames 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 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 ( 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: 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. ![]() |
|||||
35 | "FORMAT\\s+TabSeparatedWithNamesAndTypes", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+TabSeparatedWithNamesAndTypes 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 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 ( 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: 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. ![]() |
|||||
36 | "FORMAT\\s+TabSeparatedRaw", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+TabSeparatedRaw 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 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 ( 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: 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. ![]() |
|||||
37 | "FORMAT\\s+BlockTabSeparated", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+BlockTabSeparated 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 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 ( 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: 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. ![]() |
|||||
38 | "FORMAT\\s+CSVWithNames", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+CSVWithNames 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 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 ( 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: 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. ![]() |
|||||
39 | "FORMAT\\s+CSV", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+CSV 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 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 ( 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: 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. ![]() |
|||||
40 | "FORMAT\\s+JSON", |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+JSON 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 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 ( 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: 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. ![]() |
|||||
41 | "FORMAT\\s+TabSeparated" |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
FORMAT\\s+TabSeparated 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 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 ( 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: 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. ![]() |
|||||
42 | ]; |
||||
43 | |||||
44 | /** |
||||
45 | * Query constructor. |
||||
0 ignored issues
–
show
|
|||||
46 | * @param string $sql |
||||
0 ignored issues
–
show
|
|||||
47 | * @param array $degenerations |
||||
0 ignored issues
–
show
|
|||||
48 | */ |
||||
49 | 46 | public function __construct($sql, $degenerations = []) |
|||
0 ignored issues
–
show
|
|||||
50 | { |
||||
51 | 46 | if (!trim($sql)) |
|||
0 ignored issues
–
show
|
|||||
52 | { |
||||
53 | 1 | throw new QueryException('Empty Query'); |
|||
54 | } |
||||
55 | 45 | $this->sql = $sql; |
|||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 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. ![]() |
|||||
56 | 45 | $this->degenerations = $degenerations; |
|||
57 | 45 | } |
|||
58 | |||||
59 | /** |
||||
60 | * @param string|null $format |
||||
61 | */ |
||||
62 | 39 | public function setFormat($format) |
|||
0 ignored issues
–
show
|
|||||
63 | { |
||||
64 | 39 | $this->format = $format; |
|||
65 | 39 | } |
|||
0 ignored issues
–
show
|
|||||
66 | |||||
67 | |||||
68 | 39 | private function applyFormatQuery() |
|||
0 ignored issues
–
show
|
|||||
69 | { |
||||
70 | // FORMAT\s(\w)*$ |
||||
71 | 39 | if (null === $this->format) { |
|||
0 ignored issues
–
show
|
|||||
72 | return false; |
||||
73 | } |
||||
74 | 39 | $supportFormats = implode("|",$this->supportFormats); |
|||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
| 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 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 ( 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: 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. ![]() |
|||||
75 | |||||
76 | 39 | $this->sql = trim($this->sql); |
|||
0 ignored issues
–
show
|
|||||
77 | 39 | if (substr($this->sql, -1) == ';') { |
|||
0 ignored issues
–
show
|
|||||
78 | $this->sql = substr($this->sql, 0, -1); |
||||
0 ignored issues
–
show
|
|||||
79 | } |
||||
80 | |||||
81 | 39 | $matches = []; |
|||
82 | 39 | if (preg_match_all('%(' . $supportFormats . ')%ius', $this->sql, $matches)) { |
|||
0 ignored issues
–
show
|
|||||
83 | |||||
84 | // skip add "format json" |
||||
85 | 2 | if (isset($matches[0])) |
|||
86 | { |
||||
0 ignored issues
–
show
|
|||||
87 | |||||
88 | 2 | $this->format = trim(str_ireplace('format', '', $matches[0][0])); |
|||
0 ignored issues
–
show
It seems like
str_ireplace('format', '', $matches[0][0]) can also be of type array ; however, parameter $string of trim() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
89 | |||||
0 ignored issues
–
show
|
|||||
90 | } |
||||
91 | } else { |
||||
92 | 37 | $this->sql = $this->sql . ' FORMAT ' . $this->format; |
|||
0 ignored issues
–
show
|
|||||
93 | } |
||||
94 | |||||
0 ignored issues
–
show
|
|||||
95 | |||||
96 | |||||
97 | |||||
98 | |||||
99 | |||||
100 | 39 | } |
|||
0 ignored issues
–
show
|
|||||
101 | |||||
102 | /** |
||||
103 | * @return null|string |
||||
0 ignored issues
–
show
|
|||||
104 | */ |
||||
105 | 45 | public function getFormat() |
|||
0 ignored issues
–
show
|
|||||
106 | { |
||||
107 | return $this->format; |
||||
108 | 45 | } |
|||
109 | |||||
110 | public function isUseInUrlBindingsParams():bool |
||||
0 ignored issues
–
show
|
|||||
111 | 45 | { |
|||
112 | // 'query=select {p1:UInt8} + {p2:UInt8}' -F "param_p1=3" -F "param_p2=4" |
||||
113 | 45 | return preg_match('#{[\w+]+:[\w+()]+}#',$this->sql); |
|||
0 ignored issues
–
show
|
|||||
114 | 39 | ||||
115 | } |
||||
0 ignored issues
–
show
|
|||||
116 | public function getUrlBindingsParams():array |
||||
0 ignored issues
–
show
|
|||||
117 | 45 | { |
|||
118 | $out=[]; |
||||
0 ignored issues
–
show
|
|||||
119 | 45 | if (sizeof($this->degenerations)) { |
|||
0 ignored issues
–
show
|
|||||
120 | foreach ($this->degenerations as $degeneration) { |
||||
121 | 45 | if ($degeneration instanceof Degeneration) { |
|||
122 | 45 | $params=$degeneration->getBind(); |
|||
0 ignored issues
–
show
|
|||||
123 | break; |
||||
124 | // need first response |
||||
125 | } |
||||
126 | } |
||||
127 | 45 | } |
|||
128 | if (sizeof($params)) { |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
129 | foreach ($params as $key=>$value) |
||||
0 ignored issues
–
show
|
|||||
130 | { |
||||
131 | $out['param_'.$key]=$value; |
||||
0 ignored issues
–
show
|
|||||
132 | } |
||||
133 | } |
||||
134 | return $out; |
||||
0 ignored issues
–
show
|
|||||
135 | } |
||||
136 | |||||
137 | public function toSql() |
||||
0 ignored issues
–
show
|
|||||
138 | { |
||||
139 | if ($this->format !== null) { |
||||
140 | $this->applyFormatQuery(); |
||||
141 | } |
||||
142 | |||||
143 | if (sizeof($this->degenerations)) |
||||
0 ignored issues
–
show
|
|||||
144 | { |
||||
145 | foreach ($this->degenerations as $degeneration) |
||||
146 | { |
||||
147 | if ($degeneration instanceof Degeneration) { |
||||
0 ignored issues
–
show
|
|||||
148 | $this->sql = $degeneration->process($this->sql); |
||||
149 | } |
||||
150 | } |
||||
151 | } |
||||
152 | |||||
153 | return $this->sql; |
||||
154 | } |
||||
155 | |||||
156 | /** |
||||
157 | * @return string |
||||
158 | */ |
||||
159 | public function __toString() |
||||
0 ignored issues
–
show
|
|||||
160 | { |
||||
161 | return $this->toSql(); |
||||
162 | } |
||||
163 | } |
||||
164 |