Skip to content

Commit 33e754d

Browse files
committed
ok
1 parent 50f596f commit 33e754d

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

src/ClickHouseFunctions.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ public function delTypeAlias($alias)
145145
*/
146146
public function changeIfIsAlias($type_src)
147147
{
148-
static $aliases_arr = false;
148+
static $aliases_arr = [];
149149
$t_lower = \strtolower($type_src);
150-
if (!$aliases_arr || empty($type_src)) {
150+
if (empty($aliases_arr) || empty($type_src)) {
151151
$aliases_arr = $this->types_aliases;
152152
foreach ($this->types_fix_size as $canon => $v) {
153153
$aliases_arr[strtolower($canon)] = $canon;
@@ -519,13 +519,13 @@ public function getTableRowSize($table_or_fields_arr)
519519
$fields_arr = $table_or_fields_arr;
520520
$table_name = null;
521521
}
522-
$dynamic_fields = 0;
523-
$fixed_bytes = $comment = $this->countRowFixedSize($fields_arr, $dynamic_fields);
524-
if (!\is_numeric($fixed_bytes)) {
522+
$fixed_bytes = $this->countRowFixedSize($fields_arr);
523+
if (!\is_array($fixed_bytes)) {
525524
return $fixed_bytes;
526525
}
526+
\extract($fixed_bytes); // fixed_bytes, dynamic_fields
527527
$fixed_fields = \count($fields_arr) - $dynamic_fields;
528-
$comment .= " bytes in $fixed_fields FIXED FIELDS, $dynamic_fields DYNAMIC FIELDS";
528+
$comment = "$fixed_bytes bytes in $fixed_fields FIXED FIELDS, $dynamic_fields DYNAMIC FIELDS";
529529
return \compact('table_name', 'fixed_bytes', 'fixed_fields', 'dynamic_fields', 'comment');
530530
}
531531

@@ -536,9 +536,9 @@ public function getTableRowSize($table_or_fields_arr)
536536
*
537537
* @param array $fields_arr Array [field_name]=>[field_type]
538538
* @param integer $dynamic_fields (by reference)
539-
* @return integer|string Integer of fixed_bytes or string with error description
539+
* @return array|string Array of [fixed_bytes,dynamic_fields] or string with error description
540540
*/
541-
public function countRowFixedSize($fields_arr, &$dynamic_fields = 0)
541+
public function countRowFixedSize($fields_arr)
542542
{
543543
if (!\is_array($fields_arr) || !\count($fields_arr)) {
544544
return "Need array";
@@ -549,15 +549,15 @@ public function countRowFixedSize($fields_arr, &$dynamic_fields = 0)
549549
} catch (\Exception $e) {
550550
return $e->getMessage();
551551
}
552-
$sum = 0;
552+
$fixed_bytes = $dynamic_fields = 0;
553553
foreach (\array_column($parsed_arr, 'bytes') as $bytes) {
554554
if ($bytes) {
555-
$sum += $bytes;
555+
$fixed_bytes += $bytes;
556556
} else {
557557
$dynamic_fields++;
558558
}
559559
}
560-
return $sum;
560+
return compact('fixed_bytes', 'dynamic_fields');
561561
}
562562

563563
/**

src/ClickHouseQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ public function quotePar($str, $quote = "'")
601601
return (is_numeric($str) ||
602602
(($fc === '"' || $fc === "'") && ($fc === $lc)) ||
603603
(($lc === ')' && strpos($str, '(') !== false)) ||
604-
(($fc === '[' && $lc ===']'))
604+
(($fc === '[' && $lc === ']'))
605605
) ? $str : $quote . addcslashes($str, "'\t\n\r\0") . $quote;
606606
}
607607

tests/src/ClickHouseFunctionsTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,17 @@ public function testGetTableRowSize()
221221
public function testCountRowFixedSize()
222222
{
223223
$ch = $this->object;
224-
$dyna = 0;
225-
$sum = $ch->countRowFixedSize(['int16', 'int32', 'int64', 'String'], $dyna);
226-
$this->assertEquals(14, $sum);
227-
$this->assertEquals(1, $dyna);
224+
$fixed_bytes = $ch->countRowFixedSize(['int16', 'int32', 'int64', 'String']);
225+
\extract($fixed_bytes); // fixed_bytes, dynamic_fields
226+
$this->assertEquals(14, $fixed_bytes);
227+
$this->assertEquals(1, $dynamic_fields);
228228

229229
// exceptions
230-
$sum = $ch->countRowFixedSize([]);
231-
$this->assertTrue(is_string($sum));
230+
$fixed_bytes = $ch->countRowFixedSize([]);
231+
$this->assertTrue(is_string($fixed_bytes));
232232

233-
$sum = $ch->countRowFixedSize(['int16','badtype']);
234-
$this->assertTrue(is_string($sum));
233+
$fixed_bytes = $ch->countRowFixedSize(['int16','badtype']);
234+
$this->assertTrue(is_string($fixed_bytes));
235235
}
236236

237237
/**

0 commit comments

Comments
 (0)