Skip to content

Commit 8584f1b

Browse files
authored
Merge pull request #8270 from kenjis/fix-TypeError-in-strict-mode
refactor: fix TypeError in strict mode
2 parents 9208a60 + 18582cc commit 8584f1b

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

system/Commands/Database/ShowTableInfo.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,12 @@ private function showFieldMetaData(string $tableName): void
292292
CLI::table($this->tbody, $thead);
293293
}
294294

295-
private function setYesOrNo(bool $fieldValue): string
295+
/**
296+
* @param bool|int|string|null $fieldValue
297+
*/
298+
private function setYesOrNo($fieldValue): string
296299
{
297-
if ($fieldValue) {
300+
if ((bool) $fieldValue) {
298301
return CLI::color('Yes', 'green');
299302
}
300303

system/Database/BaseConnection.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -1006,10 +1006,10 @@ public function getConnectDuration(int $decimals = 6): string
10061006
* insert the table prefix (if it exists) in the proper position, and escape only
10071007
* the correct identifiers.
10081008
*
1009-
* @param array|string $item
1010-
* @param bool $prefixSingle Prefix a table name with no segments?
1011-
* @param bool $protectIdentifiers Protect table or column names?
1012-
* @param bool $fieldExists Supplied $item contains a column name?
1009+
* @param array|int|string $item
1010+
* @param bool $prefixSingle Prefix a table name with no segments?
1011+
* @param bool $protectIdentifiers Protect table or column names?
1012+
* @param bool $fieldExists Supplied $item contains a column name?
10131013
*
10141014
* @return array|string
10151015
* @phpstan-return ($item is array ? array : string)
@@ -1030,6 +1030,9 @@ public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $pro
10301030
return $escapedArray;
10311031
}
10321032

1033+
// If you pass `['column1', 'column2']`, `$item` will be int because the array keys are int.
1034+
$item = (string) $item;
1035+
10331036
// This is basically a bug fix for queries that use MAX, MIN, etc.
10341037
// If a parenthesis is found we know that we do not need to
10351038
// escape the data or add a prefix. There's probably a more graceful

system/Database/BaseUtils.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ public function getCSVFromResult(ResultInterface $query, string $delim = ',', st
212212
$line = [];
213213

214214
foreach ($row as $item) {
215-
$line[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $item ?? '') . $enclosure;
215+
$line[] = $enclosure . str_replace(
216+
$enclosure,
217+
$enclosure . $enclosure,
218+
(string) $item
219+
) . $enclosure;
216220
}
217221

218222
$out .= implode($delim, $line) . $newline;
@@ -244,7 +248,7 @@ public function getXMLFromResult(ResultInterface $query, array $params = []): st
244248
$xml .= $tab . '<' . $element . '>' . $newline;
245249

246250
foreach ($row as $key => $val) {
247-
$val = (! empty($val)) ? xml_convert($val) : '';
251+
$val = (! empty($val)) ? xml_convert((string) $val) : '';
248252

249253
$xml .= $tab . $tab . '<' . $key . '>' . $val . '</' . $key . '>' . $newline;
250254
}

system/Database/Postgre/Builder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,11 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
355355
// autoincrement identity field must use DEFAULT and not NULL
356356
// this could be removed in favour of leaving to developer but does make things easier and function like other DBMS
357357
foreach ($constraints as $constraint) {
358-
$key = array_search(trim($constraint, '"'), $fieldNames, true);
358+
$key = array_search(trim((string) $constraint, '"'), $fieldNames, true);
359359

360360
if ($key !== false) {
361361
foreach ($values as $arrayKey => $value) {
362-
if (strtoupper($value[$key]) === 'NULL') {
362+
if (strtoupper((string) $value[$key]) === 'NULL') {
363363
$values[$arrayKey][$key] = 'DEFAULT';
364364
}
365365
}

system/Database/SQLSRV/Connection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ protected function _escapeString(string $str): string
190190
*/
191191
public function insertID(): int
192192
{
193-
return $this->query('SELECT SCOPE_IDENTITY() AS insert_id')->getRow()->insert_id ?? 0;
193+
return (int) ($this->query('SELECT SCOPE_IDENTITY() AS insert_id')->getRow()->insert_id ?? 0);
194194
}
195195

196196
/**

0 commit comments

Comments
 (0)