Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: fix TypeError in strict mode #8270

Merged
merged 6 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions system/Commands/Database/ShowTableInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,12 @@ private function showFieldMetaData(string $tableName): void
CLI::table($this->tbody, $thead);
}

private function setYesOrNo(bool $fieldValue): string
/**
* @param bool|int|string|null $fieldValue
*/
private function setYesOrNo($fieldValue): string
{
if ($fieldValue) {
if ((bool) $fieldValue) {
return CLI::color('Yes', 'green');
}

Expand Down
11 changes: 7 additions & 4 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1006,10 +1006,10 @@ public function getConnectDuration(int $decimals = 6): string
* insert the table prefix (if it exists) in the proper position, and escape only
* the correct identifiers.
*
* @param array|string $item
* @param bool $prefixSingle Prefix a table name with no segments?
* @param bool $protectIdentifiers Protect table or column names?
* @param bool $fieldExists Supplied $item contains a column name?
* @param array|int|string $item
* @param bool $prefixSingle Prefix a table name with no segments?
* @param bool $protectIdentifiers Protect table or column names?
* @param bool $fieldExists Supplied $item contains a column name?
*
* @return array|string
* @phpstan-return ($item is array ? array : string)
Expand All @@ -1030,6 +1030,9 @@ public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $pro
return $escapedArray;
}

// If you pass `['column1', 'column2']`, `$item` will be int because the array keys are int.
$item = (string) $item;

// This is basically a bug fix for queries that use MAX, MIN, etc.
// If a parenthesis is found we know that we do not need to
// escape the data or add a prefix. There's probably a more graceful
Expand Down
8 changes: 6 additions & 2 deletions system/Database/BaseUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ public function getCSVFromResult(ResultInterface $query, string $delim = ',', st
$line = [];

foreach ($row as $item) {
$line[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $item ?? '') . $enclosure;
$line[] = $enclosure . str_replace(
$enclosure,
$enclosure . $enclosure,
(string) $item
) . $enclosure;
}

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

foreach ($row as $key => $val) {
$val = (! empty($val)) ? xml_convert($val) : '';
$val = (! empty($val)) ? xml_convert((string) $val) : '';

$xml .= $tab . $tab . '<' . $key . '>' . $val . '</' . $key . '>' . $newline;
}
Expand Down
4 changes: 2 additions & 2 deletions system/Database/Postgre/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,11 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
// autoincrement identity field must use DEFAULT and not NULL
// this could be removed in favour of leaving to developer but does make things easier and function like other DBMS
foreach ($constraints as $constraint) {
$key = array_search(trim($constraint, '"'), $fieldNames, true);
$key = array_search(trim((string) $constraint, '"'), $fieldNames, true);

if ($key !== false) {
foreach ($values as $arrayKey => $value) {
if (strtoupper($value[$key]) === 'NULL') {
if (strtoupper((string) $value[$key]) === 'NULL') {
$values[$arrayKey][$key] = 'DEFAULT';
}
}
Expand Down
2 changes: 1 addition & 1 deletion system/Database/SQLSRV/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ protected function _escapeString(string $str): string
*/
public function insertID(): int
{
return $this->query('SELECT SCOPE_IDENTITY() AS insert_id')->getRow()->insert_id ?? 0;
return (int) ($this->query('SELECT SCOPE_IDENTITY() AS insert_id')->getRow()->insert_id ?? 0);
}

/**
Expand Down
Loading